[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <56e74264-6f98-4216-9f9a-e8f718375602@redhat.com>
Date: Thu, 14 Dec 2023 10:16:47 +0100
From: Hans de Goede <hdegoede@...hat.com>
To: Andy Shevchenko <andy.shevchenko@...il.com>,
George Stark <gnstark@...utedevices.com>
Cc: pavel@....cz, lee@...nel.org, vadimp@...dia.com,
mpe@...erman.id.au, npiggin@...il.com, christophe.leroy@...roup.eu,
mazziesaccount@...il.com, peterz@...radead.org, mingo@...hat.com,
will@...nel.org, longman@...hat.com, boqun.feng@...il.com,
nikitos.tr@...il.com, linux-leds@...r.kernel.org,
linux-kernel@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
kernel@...utedevices.com
Subject: Re: [PATCH v3 03/11] devm-helpers: introduce devm_mutex_init
Hi,
On 12/13/23 23:38, Andy Shevchenko wrote:
> On Thu, Dec 14, 2023 at 12:36 AM Andy Shevchenko
> <andy.shevchenko@...il.com> wrote:
>> On Thu, Dec 14, 2023 at 12:30 AM George Stark <gnstark@...utedevices.com> wrote:
>>>
>>> Using of devm API leads to a certain order of releasing resources.
>>> So all dependent resources which are not devm-wrapped should be deleted
>>> with respect to devm-release order. Mutex is one of such objects that
>>> often is bound to other resources and has no own devm wrapper.
>>> Since mutex_destroy() actually does nothing in non-debug builds
>>> frequently calling mutex_destroy() is just ignored which is safe for now
>>> but wrong formally and can lead to a problem if mutex_destroy() is
>>> extended so introduce devm_mutex_init().
>
> ...
>
>>> +#ifdef mutex_destroy
>>> +static inline void devm_mutex_release(void *res)
>>> +{
>>> + mutex_destroy(res);
>>> +}
>>> +#endif
>>> +
>>> +/**
>>> + * devm_mutex_init - Resource-managed mutex initialization
>>> + * @dev: Device which lifetime mutex is bound to
>>> + * @lock: Pointer to a mutex
>>> + *
>>> + * Initialize mutex which is automatically destroyed when the driver is detached.
>>> + *
>>> + * Returns: 0 on success or a negative error code on failure.
>>> + */
>>> +static inline int devm_mutex_init(struct device *dev, struct mutex *lock)
>>> +{
>>> + mutex_init(lock);
>>> +#ifdef mutex_destroy
>>> + return devm_add_action_or_reset(dev, devm_mutex_release, lock);
>>> +#else
>>> + return 0;
>>> +#endif
>>> +}
>>
>> If this is going to be accepted, you may decrease the amount of ifdeffery.
>>
>> #ifdef ...
>> #else
>> #define devm_mutex_init(dev, lock) mutex_init(lock)
>
> More precisely ({ mutex_init(lock); 0; }) or as a static inline...
With a static inline we are pretty much back to the original
v3 patch.
I believe the best way to reduce the ifdef-ery is to remove
the #ifdef around devm_mutex_release() having unused
static inline ... functions in .h files is quite common,
so this one does not need a #ifdef around it and with
that removed we are down to just one #ifdef so just
removing the #ifdef around devm_mutex_release() seems
the best fix.
With that fixed you may add my:
Reviewed-by: Hans de Goede <hdegoede@...hat.com>
to the patch and I'm fine with this being routed
upstream through whatever tree is convenient.
Regards,
Hans
Powered by blists - more mailing lists