Re: [PATCH] regmap : make lock/unlock functions customizable.

Davide Ciminaghi
2012-10-12T08:24:22Z

On Fri, Oct 12, 2012 at 03:26:09PM +0900, Mark Brown wrote:
> On Mon, Oct 01, 2012 at 11:31:04PM +0200, ciminaghi@gnudd.com wrote:
> > From: Davide Ciminaghi <ciminaghi@gnudd.com>
> >
> > It is sometimes convenient for a regmap user to override the standard
> > regmap lock/unlock functions with custom functions.
>
> This looks good overall but...
>
> > -static void regmap_lock_mutex(struct regmap *map)
> > +static void regmap_lock_mutex(void *__map)
> > {
> > + struct regmap *map = (struct regmap *)__map;
> > mutex_lock(&map->mutex);
>
> ...you should never need to cast away from or to void, if you do there's
> a bug somewhere.

regmap lock/unlock original functions just received a struct regmap * .
I needed a void * for the customized version of such functions, so just
replaced struct regmap * with void *

typedef void (*regmap_lock)(void *);
typedef void (*regmap_unlock)(void *);

The cast isn't actually needed (code compiles with no warnings without it).
I could also do something like this, if you think it's better:

typedef void (*regmap_lock)(struct regmap *, void *);
typedef void (*regmap_unlock)(struct regmap *, void *);

and then ignore the second argument in the default version of the functions.

Thanks and regards
Davide