Linux Input/HID development
 help / color / mirror / Atom feed
From: "Rafael Passos" <rafael@rcpassos.me>
To: "David Rheinsberg" <david@readahead.eu>,
	"Rafael Passos" <rafael@rcpassos.me>,
	"Jiri Kosina" <jikos@kernel.org>,
	"Benjamin Tissoires" <bentiss@kernel.org>
Cc: "Shuah Khan" <skhan@linuxfoundation.org>,
	"Brigham Campbell" <me@brighamcampbell.com>,
	"Jori Koolstra" <jkoolstra@xs4all.nl>,
	<linux-input@vger.kernel.org>
Subject: Re: [PATCH v3 1/4] HID: wiimote: turn on the LEDs indicating the controller id
Date: Sat, 01 Aug 2026 21:21:32 -0300	[thread overview]
Message-ID: <DKE11FVZYDCW.1UEUU1GSXHP3B@rcpassos.me> (raw)
In-Reply-To: <6ffe2879-5d76-42b3-bd65-2180967d1498@app.fastmail.com>

On Fri Jul 31, 2026 at 6:02 AM -03, David Rheinsberg wrote:
>> -	hid_info(hdev, "New device registered\n");
>> +	player_id = ida_alloc_min(&wiimote_ida, 1, GFP_KERNEL);
>> +	if (player_id < 1) {
>> +		hid_err(hdev, "cannot allocate controller id\n");
>> +		ret = player_id;
>> +		goto err_free;
>> +	}
>> +
>> +	wdata->player_id = player_id;
>> +
>> +	hid_info(hdev, "New device registered (Wiimote %d)\n", player_id);
>
> `wiimote_create()` should initialize `wdata->player_id` to -1, so `ida_free()` is a no-op in the `err_free` path. Right now it is implicitly initialized to 0, and thus ida_free() will warn about an unallocated ID.
>
> Also: Why not just use IDs starting from 0?

I chose to start from 1 to avoid "id 0 = player 1".

Wouldn't setting an u8 to -1 result into 255 ? If so,
this would not be a no-op. Also, comparing player_id < 0 would never be
true. If the IDA starts from 0, there is no usable "empty value" in a u8
when deciding if I should call ida_free.
If I let "failure" to be 0, I can just use this in destroy:

if (wdata->player_id)
	ida_free(&wiimote_ida, wdata->player_id);


Thanks,
Rafael

  reply	other threads:[~2026-08-02  0:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 16:49 [PATCH v3 0/4] HID: wiimote: new LED behavior on connect, scoped guards, uaf Rafael Passos
2026-07-29 16:49 ` [PATCH v3 1/4] HID: wiimote: turn on the LEDs indicating the controller id Rafael Passos
2026-07-29 17:07   ` sashiko-bot
2026-07-31  9:02   ` David Rheinsberg
2026-08-02  0:21     ` Rafael Passos [this message]
2026-08-06  8:01       ` David Rheinsberg
2026-07-29 16:49 ` [PATCH v3 2/4] HID: wiimote: replace spinlock pairs with scoped_guard Rafael Passos
2026-07-29 17:07   ` sashiko-bot
2026-07-31  9:08   ` David Rheinsberg
2026-07-29 16:49 ` [PATCH v3 3/4] HID: wiimote: use scoped cleanup in wiimote and led probes Rafael Passos
2026-07-29 17:14   ` sashiko-bot
2026-07-31 11:18   ` David Rheinsberg
2026-08-02  0:24     ` Rafael Passos
2026-07-29 16:49 ` [PATCH v3 4/4] HID: wiimote: fix uaf when hid events are handled during destroy Rafael Passos
2026-07-29 17:14   ` sashiko-bot
2026-07-31 11:17   ` David Rheinsberg

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=DKE11FVZYDCW.1UEUU1GSXHP3B@rcpassos.me \
    --to=rafael@rcpassos.me \
    --cc=bentiss@kernel.org \
    --cc=david@readahead.eu \
    --cc=jikos@kernel.org \
    --cc=jkoolstra@xs4all.nl \
    --cc=linux-input@vger.kernel.org \
    --cc=me@brighamcampbell.com \
    --cc=skhan@linuxfoundation.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