* Re: [PATCH v5 6/6] i2c: Add driver for the RTL9300 I2C controller
[not found] ` <0c94d0fc-dc0c-4e35-a6c1-2d7e01a3eb43@alliedtelesis.co.nz>
@ 2024-09-30 7:55 ` Markus Elfring
2024-09-30 8:12 ` Javier Carrasco
0 siblings, 1 reply; 2+ messages in thread
From: Markus Elfring @ 2024-09-30 7:55 UTC (permalink / raw)
To: Chris Packham, linux-i2c, linux-pm, linux-mips, devicetree,
Andi Shyti, Conor Dooley, Krzysztof Kozlowski, Lee Jones,
Rob Herring, Sebastian Reichel, Thomas Bogendörfer
Cc: LKML, linux-doc, kernel-janitors, Javier Carrasco Cruz,
Peter Zijlstra
>> …
>>> +++ b/drivers/i2c/busses/i2c-rtl9300.c
>>> @@ -0,0 +1,422 @@
>> …
>>> +static int rtl9300_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags,
>>> + char read_write, u8 command, int size,
>>> + union i2c_smbus_data *data)
>>> +{
>> …
>>> + mutex_lock(&i2c->lock);
>>> + if (chan->sda_pin != i2c->sda_pin) {
>> …
>>> +out_unlock:
>>> + mutex_unlock(&i2c->lock);
>>> +
>>> + return ret;
>>> +}
>> …
>>
>> Under which circumstances would you become interested to apply a statement
>> like “guard(mutex)(&i2c->lock);”?
>> https://elixir.bootlin.com/linux/v6.11/source/include/linux/mutex.h#L196
>
> At this stage I don't what to change unless Andi insists that I do.
>
> I can't find much mention of using guard() on https://www.kernel.org/doc/html/latest/
Do you find any other information sources more encouraging?
> but I can see enough examples (although notably none in drivers/i2c) that I _think_ I can see how I could use it.
See also (for example):
Article “Linux Kernel Development - Automatic Cleanup”
by Javier Carrasco Cruz
2024-06-17
https://javiercarrascocruz.github.io/kernel-auto-cleanup-2#2-automatic-mutex-handling
Regards,
Markus
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v5 6/6] i2c: Add driver for the RTL9300 I2C controller
2024-09-30 7:55 ` [PATCH v5 6/6] i2c: Add driver for the RTL9300 I2C controller Markus Elfring
@ 2024-09-30 8:12 ` Javier Carrasco
0 siblings, 0 replies; 2+ messages in thread
From: Javier Carrasco @ 2024-09-30 8:12 UTC (permalink / raw)
To: Markus Elfring, Chris Packham, linux-i2c, linux-pm, linux-mips,
devicetree, Andi Shyti, Conor Dooley, Krzysztof Kozlowski,
Lee Jones, Rob Herring, Sebastian Reichel,
Thomas Bogendörfer
Cc: LKML, linux-doc, kernel-janitors, Peter Zijlstra
On 30/09/2024 09:55, Markus Elfring wrote:
>>> …
>>>> +++ b/drivers/i2c/busses/i2c-rtl9300.c
>>>> @@ -0,0 +1,422 @@
>>> …
>>>> +static int rtl9300_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags,
>>>> + char read_write, u8 command, int size,
>>>> + union i2c_smbus_data *data)
>>>> +{
>>> …
>>>> + mutex_lock(&i2c->lock);
>>>> + if (chan->sda_pin != i2c->sda_pin) {
>>> …
>>>> +out_unlock:
>>>> + mutex_unlock(&i2c->lock);
>>>> +
>>>> + return ret;
>>>> +}
>>> …
>>>
>>> Under which circumstances would you become interested to apply a statement
>>> like “guard(mutex)(&i2c->lock);”?
>>> https://elixir.bootlin.com/linux/v6.11/source/include/linux/mutex.h#L196
>>
>> At this stage I don't what to change unless Andi insists that I do.
>>
>> I can't find much mention of using guard() on https://www.kernel.org/doc/html/latest/
>
> Do you find any other information sources more encouraging?
>
>
>> but I can see enough examples (although notably none in drivers/i2c) that I _think_ I can see how I could use it.
>
> See also (for example):
> Article “Linux Kernel Development - Automatic Cleanup”
> by Javier Carrasco Cruz
> 2024-06-17
> https://javiercarrascocruz.github.io/kernel-auto-cleanup-2#2-automatic-mutex-handling
>
> Regards,
> Markus
My personal blog is definitely NOT an official or even reliable source
of information.
Thanks for referencing it, but please look for examples of guard() in
the kernel, because there are several examples for different kind of
mutexes. For example, IIO uses them widely. And they are really nice, so
I would recommend anyone using them whenever it makes sense.
Best regards,
Javier Carrasco
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-09-30 8:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20240925215847.3594898-7-chris.packham@alliedtelesis.co.nz>
[not found] ` <096aebcd-778c-4160-b478-bb26025f3940@web.de>
[not found] ` <0c94d0fc-dc0c-4e35-a6c1-2d7e01a3eb43@alliedtelesis.co.nz>
2024-09-30 7:55 ` [PATCH v5 6/6] i2c: Add driver for the RTL9300 I2C controller Markus Elfring
2024-09-30 8:12 ` Javier Carrasco
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox