On 2/13/21 7:03 AM, Hans de Goede wrote:
[ ... ]
> 
> I think something like this should work:
> 
> static int devm_delayed_work_autocancel(struct device *dev, struct 
> delayed_work *w,
>                                       void (*worker)(struct work_struct 
> *work)) {
>       INIT_DELAYED_WORK(w, worker);
>       return devm_add_action(dev, (void (*action)(void 
> *))cancel_delayed_work_sync, w);
> }
> 
> I'm not sure about the cast, that may need something like this instead:
> 
> typedef void (*devm_action_func)(void *);
> 
> static int devm_delayed_work_autocancel(struct device *dev, struct 
> delayed_work *w,
>                                       void (*worker)(struct work_struct 
> *work)) {
>       INIT_DELAYED_WORK(w, worker);
>       return devm_add_action(dev, (devm_action_func)cancel_delayed_work_sync, 
> w);

Unfortunately, you can not type cast function pointers in C. It is against the 
C ABI.
I am sure it is done in a few places in the kernel anyway, but those are wrong.

This is the reason why many calls to devm_add_action() point to functions such 
as

static void visconti_clk_disable_unprepare(void *data)
{
        clk_disable_unprepare(data);
}

which could otherwise be handled using typecasts.

Guenter

Reply via email to