From: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
To: Benjamin Tissoires <bentiss@kernel.org>
Cc: Roderick Colenbrander <roderick.colenbrander@sony.com>,
Jiri Kosina <jikos@kernel.org>,
Henrik Rydberg <rydberg@bitmath.org>,
kernel@collabora.com, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 03/11] HID: playstation: Simplify locking with guard() and scoped_guard()
Date: Tue, 23 Sep 2025 00:04:59 +0300 [thread overview]
Message-ID: <e9c9685a-6c8c-4f2b-a89c-e20cbbff370f@collabora.com> (raw)
In-Reply-To: <7fp3kik4b6wtzp65ir3bz5bw5r5qrjzi2nahwxkszjfptmsuyb@eoja4452cryb>
Hi Benjamin,
Thank you for reviewing the series and sorry for my late reply, I've just
returned from vacation.
On 9/17/25 5:21 PM, Benjamin Tissoires wrote:
> On Sep 17 2025, Benjamin Tissoires wrote:
>> On Jun 25 2025, Cristian Ciocaltea wrote:
>>> Use guard() and scoped_guard() infrastructure instead of explicitly
>>> acquiring and releasing spinlocks and mutexes to simplify the code and
>>> ensure that all locks are released properly.
>>>
>>> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
>>
>> It looks like the patch is now creating sparse errors:
>>
>> https://gitlab.freedesktop.org/bentiss/hid/-/jobs/84636162
>>
>> with:
>>
>> drivers/hid/hid-playstation.c:1187:32: warning: context imbalance in 'dualsense_player_led_set_brightness' - wrong count at exit
>> drivers/hid/hid-playstation.c:1403:9: warning: context imbalance in 'dualsense_parse_report' - different lock contexts for basic block
>> drivers/hid/hid-playstation.c:1499:12: warning: context imbalance in 'dualsense_play_effect' - different lock contexts for basic block
>> drivers/hid/hid-playstation.c:1552:13: warning: context imbalance in 'dualsense_set_lightbar' - wrong count at exit
>> drivers/hid/hid-playstation.c:1564:13: warning: context imbalance in 'dualsense_set_player_leds' - wrong count at exit
>> drivers/hid/hid-playstation.c:2054:33: warning: context imbalance in 'dualshock4_led_set_blink' - wrong count at exit
>> drivers/hid/hid-playstation.c:2095:33: warning: context imbalance in 'dualshock4_led_set_brightness' - wrong count at exit
>> drivers/hid/hid-playstation.c:2463:12: warning: context imbalance in 'dualshock4_play_effect' - different lock contexts for basic block
>> drivers/hid/hid-playstation.c:2501:13: warning: context imbalance in 'dualshock4_set_bt_poll_interval' - wrong count at exit
>> drivers/hid/hid-playstation.c:2509:13: warning: context imbalance in 'dualshock4_set_default_lightbar_colors' - wrong count at exit
>>
>> (the artifacts are going to be removed in 4 hours, so better document
>> the line numbers here).
>>
>> I am under the impression that it's because the 2 *_output_worker
>> functions are not using scoped guarding, but it could very well be
>> something entirely different. Do you mind taking a look as well?
>
> Turns out it's the mix of guard and scoped_guard that confuses spare:
> https://lkml.org/lkml/2025/6/8/74
>
> the following shuts down all of the warnings:
Indeed, I think that would be the best workaround for now. At least I couldn't
find anything better while experimenting with latest sparse commit 0196afe16a50
("Merge branch 'riscv'") - which is still almost 2 years old btw.
>
> ---
>
> diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
> index d2bee1a314b1..36f3ac044fdc 100644
> --- a/drivers/hid/hid-playstation.c
> +++ b/drivers/hid/hid-playstation.c
> @@ -1274,9 +1274,9 @@ static void dualsense_init_output_report(struct dualsense *ds,
>
> static inline void dualsense_schedule_work(struct dualsense *ds)
> {
> - guard(spinlock_irqsave)(&ds->base.lock);
> - if (ds->output_worker_initialized)
> - schedule_work(&ds->output_worker);
> + scoped_guard(spinlock_irqsave, &ds->base.lock)
> + if (ds->output_worker_initialized)
> + schedule_work(&ds->output_worker);
> }
>
> /*
> @@ -2626,9 +2626,9 @@ static void dualshock4_remove(struct ps_device *ps_dev)
>
> static inline void dualshock4_schedule_work(struct dualshock4 *ds4)
> {
> - guard(spinlock_irqsave)(&ds4->base.lock);
> - if (ds4->output_worker_initialized)
> - schedule_work(&ds4->output_worker);
> + scoped_guard(spinlock_irqsave, &ds4->base.lock)
> + if (ds4->output_worker_initialized)
> + schedule_work(&ds4->output_worker);
> }
>
> static void dualshock4_set_bt_poll_interval(struct dualshock4 *ds4, u8 interval)
>
> ---
>
> There are also a couple more of manual spin_unlock_irqrestore which
> would benefit from the scoped guard mechanism.
Oh, my bad, I somehow missed to mention in the commit description that I
intentionally omitted those residing in {dualsense|dualshock4}_output_worker()
as the functions do already contain plenty of long statements and adding yet
another level of indentation would affect readability in a negative way.
I've just checked it again and it doesn't really look that bad. Consistency
should be more important, anyway, hence let's convert them as well.
Regards,
Cristian
next prev parent reply other threads:[~2025-09-22 21:05 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-24 21:56 [PATCH v2 00/11] HID: playstation: Add support for audio jack handling on DualSense Cristian Ciocaltea
2025-06-24 21:56 ` [PATCH v2 01/11] HID: playstation: Make use of bitfield macros Cristian Ciocaltea
2025-06-24 21:56 ` [PATCH v2 02/11] HID: playstation: Add spaces around arithmetic operators Cristian Ciocaltea
2025-06-24 21:56 ` [PATCH v2 03/11] HID: playstation: Simplify locking with guard() and scoped_guard() Cristian Ciocaltea
2025-09-17 13:50 ` Benjamin Tissoires
2025-09-17 14:21 ` Benjamin Tissoires
2025-09-22 21:04 ` Cristian Ciocaltea [this message]
2025-06-24 21:56 ` [PATCH v2 04/11] HID: playstation: Replace uint{32,16,8}_t with u{32,16,8} Cristian Ciocaltea
2025-06-24 21:56 ` [PATCH v2 05/11] HID: playstation: Correct spelling in comment sections Cristian Ciocaltea
2025-06-24 21:56 ` [PATCH v2 06/11] HID: playstation: Fix all alignment and line length issues Cristian Ciocaltea
2025-06-24 21:56 ` [PATCH v2 07/11] HID: playstation: Document spinlock_t usage Cristian Ciocaltea
2025-06-24 21:56 ` [PATCH v2 08/11] HID: playstation: Prefer kzalloc(sizeof(*buf)...) Cristian Ciocaltea
2025-06-24 21:56 ` [PATCH v2 09/11] HID: playstation: Redefine DualSense input report status field Cristian Ciocaltea
2025-06-24 21:56 ` [PATCH v2 10/11] HID: playstation: Support DualSense audio jack hotplug detection Cristian Ciocaltea
2025-06-24 21:56 ` [PATCH v2 11/11] HID: playstation: Support DualSense audio jack event reporting Cristian Ciocaltea
2025-07-03 7:48 ` [PATCH v2 00/11] HID: playstation: Add support for audio jack handling on DualSense Jiri Kosina
2025-07-10 5:24 ` Cristian Ciocaltea
2025-07-10 21:31 ` Roderick Colenbrander
2025-07-22 5:47 ` Roderick Colenbrander
2025-07-22 6:18 ` Roderick Colenbrander
2025-07-22 8:03 ` Cristian Ciocaltea
2025-07-23 4:04 ` Roderick Colenbrander
2025-07-23 4:20 ` Roderick Colenbrander
2025-07-23 7:17 ` Cristian Ciocaltea
2025-08-27 6:36 ` Cristian Ciocaltea
2025-09-12 15:38 ` Jiri Kosina
2025-09-12 16:14 ` Benjamin Tissoires
2025-09-12 17:04 ` Benjamin Tissoires
2025-07-22 7:24 ` Cristian Ciocaltea
2025-09-17 9:34 ` Jiri Kosina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e9c9685a-6c8c-4f2b-a89c-e20cbbff370f@collabora.com \
--to=cristian.ciocaltea@collabora.com \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=kernel@collabora.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=roderick.colenbrander@sony.com \
--cc=rydberg@bitmath.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).