Re: [RFC v2] ff-memless-next driver

From: Joe Perches
Date: Sat Dec 21 2013 - 18:05:48 EST


Refactoring can help reduce the line lengths.

For example:

Move the get_envelope function.
Use get_envelope in set_envelope_times.
---
drivers/input/ff-memless-next.c | 58 +++++++++++++++++++----------------------
1 file changed, 27 insertions(+), 31 deletions(-)

diff --git a/drivers/input/ff-memless-next.c b/drivers/input/ff-memless-next.c
index 722601a..73e1127 100644
--- a/drivers/input/ff-memless-next.c
+++ b/drivers/input/ff-memless-next.c
@@ -104,34 +104,46 @@ static int mlnx_upload_conditional(struct mlnx_device *mlnxdev,
return mlnxdev->control_effect(mlnxdev->dev, mlnxdev->private, &ecmd);
}

+static const struct ff_envelope *mlnx_get_envelope(const struct ff_effect *effect)
+{
+ static const struct ff_envelope empty;
+
+ switch (effect->type) {
+ case FF_CONSTANT:
+ return &effect->u.constant.envelope;
+ case FF_PERIODIC:
+ return &effect->u.periodic.envelope;
+ case FF_RAMP:
+ return &effect->u.ramp.envelope;
+ default:
+ return ∅
+ }
+}
+
static void mlnx_set_envelope_times(struct mlnx_effect *mlnxeff)
{
const struct ff_effect *effect = &mlnxeff->effect;
+ const struct ff_envelope *env;

switch (effect->type) {
- case FF_CONSTANT:
- if (effect->u.constant.envelope.attack_length)
- mlnxeff->attack_stop = mlnxeff->begin_at + msecs_to_jiffies(effect->u.constant.envelope.attack_length);
- if (effect->replay.length && effect->u.constant.envelope.fade_length)
- mlnxeff->fade_begin = mlnxeff->stop_at - msecs_to_jiffies(effect->u.constant.envelope.fade_length);
- break;
case FF_PERIODIC:
pr_debug("Phase: %u, Offset: %d\n",
effect->u.periodic.phase, effect->u.periodic.offset);
- if (effect->u.periodic.envelope.attack_length)
- mlnxeff->attack_stop = mlnxeff->begin_at + msecs_to_jiffies(effect->u.periodic.envelope.attack_length);
- if (effect->replay.length && effect->u.periodic.envelope.fade_length)
- mlnxeff->fade_begin = mlnxeff->stop_at - msecs_to_jiffies(effect->u.periodic.envelope.fade_length);
break;
+ case FF_CONSTANT:
case FF_RAMP:
- if (effect->u.ramp.envelope.attack_length)
- mlnxeff->attack_stop = mlnxeff->begin_at + msecs_to_jiffies(effect->u.ramp.envelope.attack_length);
- if (effect->replay.length && effect->u.ramp.envelope.fade_length)
- mlnxeff->fade_begin = mlnxeff->stop_at - msecs_to_jiffies(effect->u.ramp.envelope.fade_length);
break;
default:
- break;
+ return;
}
+
+ env = mlnx_get_envelope(effect);
+ if (env->attack_length)
+ mlnxeff->attack_stop = mlnxeff->begin_at +
+ msecs_to_jiffies(env->attack_length);
+ if (effect->replay.length && env->fade_length)
+ mlnxeff->fade_begin = mlnxeff->stop_at -
+ msecs_to_jiffies(env->fade_length);
}

static void mlnx_set_trip_times(struct mlnx_effect *mlnxeff,
@@ -185,22 +197,6 @@ static void mlnx_stop_effect(struct mlnx_device *mlnxdev,
}
}

-static const struct ff_envelope *mlnx_get_envelope(const struct ff_effect *effect)
-{
- static const struct ff_envelope empty;
-
- switch (effect->type) {
- case FF_CONSTANT:
- return &effect->u.constant.envelope;
- case FF_PERIODIC:
- return &effect->u.periodic.envelope;
- case FF_RAMP:
- return &effect->u.ramp.envelope;
- default:
- return ∅
- }
-}
-
static s32 mlnx_apply_envelope(const struct mlnx_effect *mlnxeff,
const s32 level)
{


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/