Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH] HID: core: Fix size_t specifier in hid_report_raw_event()
@ 2026-05-17  4:51 Nathan Chancellor
  2026-05-18  9:10 ` Geert Uytterhoeven
  0 siblings, 1 reply; 3+ messages in thread
From: Nathan Chancellor @ 2026-05-17  4:51 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: Greg Kroah-Hartman, Johan Hovold, linux-input, linux-kernel,
	stable, Miguel Ojeda, Nathan Chancellor

When building for 32-bit platforms, for which 'size_t' is
'unsigned int', there are warnings around using the incorrect format
specifier to print bsize in hid_report_raw_event():

  drivers/hid/hid-core.c:2054:29: error: format specifies type 'long' but the argument has type 'size_t' (aka 'unsigned int') [-Werror,-Wformat]
   2053 |                 hid_warn_ratelimited(hid, "Event data for report %d is incorrect (%d vs %ld)\n",
        |                                                                                         ~~~
        |                                                                                         %zu
   2054 |                                      report->id, csize, bsize);
        |                                                         ^~~~~
  drivers/hid/hid-core.c:2076:29: error: format specifies type 'long' but the argument has type 'size_t' (aka 'unsigned int') [-Werror,-Wformat]
   2075 |                 hid_warn_ratelimited(hid, "Event data for report %d was too short (%d vs %ld)\n",
        |                                                                                          ~~~
        |                                                                                          %zu
   2076 |                                      report->id, rsize, bsize);
        |                                                         ^~~~~

Use the proper 'size_t' format specifier, '%zu', to clear up the
warnings.

Cc: stable@vger.kernel.org
Fixes: 2c85c61d1332 ("HID: pass the buffer size to hid_report_raw_event")
Reported-by: Miguel Ojeda <ojeda@kernel.org>
Closes: https://lore.kernel.org/20260516020430.110135-1-ojeda@kernel.org/
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 drivers/hid/hid-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index b3596851c719..41a79e43c82b 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2050,7 +2050,7 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *
 		return 0;
 
 	if (unlikely(bsize < csize)) {
-		hid_warn_ratelimited(hid, "Event data for report %d is incorrect (%d vs %ld)\n",
+		hid_warn_ratelimited(hid, "Event data for report %d is incorrect (%d vs %zu)\n",
 				     report->id, csize, bsize);
 		return -EINVAL;
 	}
@@ -2072,7 +2072,7 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *
 		rsize = max_buffer_size;
 
 	if (bsize < rsize) {
-		hid_warn_ratelimited(hid, "Event data for report %d was too short (%d vs %ld)\n",
+		hid_warn_ratelimited(hid, "Event data for report %d was too short (%d vs %zu)\n",
 				     report->id, rsize, bsize);
 		return -EINVAL;
 	}

---
base-commit: 64ffa2e5e02ff54b23221d0282155f37283fabea
change-id: 20260517-hid-core-fix-size_t-specifier-14daf3b496b6

Best regards,
--  
Cheers,
Nathan


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] HID: core: Fix size_t specifier in hid_report_raw_event()
  2026-05-17  4:51 [PATCH] HID: core: Fix size_t specifier in hid_report_raw_event() Nathan Chancellor
@ 2026-05-18  9:10 ` Geert Uytterhoeven
  2026-05-18 19:08   ` Nathan Chancellor
  0 siblings, 1 reply; 3+ messages in thread
From: Geert Uytterhoeven @ 2026-05-18  9:10 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Jiri Kosina, Benjamin Tissoires, Greg Kroah-Hartman, Johan Hovold,
	linux-input, linux-kernel, stable, Miguel Ojeda

Hi Nathan,

On Sun, 17 May 2026 at 06:51, Nathan Chancellor <nathan@kernel.org> wrote:
> When building for 32-bit platforms, for which 'size_t' is
> 'unsigned int', there are warnings around using the incorrect format
> specifier to print bsize in hid_report_raw_event():
>
>   drivers/hid/hid-core.c:2054:29: error: format specifies type 'long' but the argument has type 'size_t' (aka 'unsigned int') [-Werror,-Wformat]
>    2053 |                 hid_warn_ratelimited(hid, "Event data for report %d is incorrect (%d vs %ld)\n",
>         |                                                                                         ~~~
>         |                                                                                         %zu
>    2054 |                                      report->id, csize, bsize);
>         |                                                         ^~~~~
>   drivers/hid/hid-core.c:2076:29: error: format specifies type 'long' but the argument has type 'size_t' (aka 'unsigned int') [-Werror,-Wformat]
>    2075 |                 hid_warn_ratelimited(hid, "Event data for report %d was too short (%d vs %ld)\n",
>         |                                                                                          ~~~
>         |                                                                                          %zu
>    2076 |                                      report->id, rsize, bsize);
>         |                                                         ^~~~~
>
> Use the proper 'size_t' format specifier, '%zu', to clear up the
> warnings.
>
> Cc: stable@vger.kernel.org
> Fixes: 2c85c61d1332 ("HID: pass the buffer size to hid_report_raw_event")
> Reported-by: Miguel Ojeda <ojeda@kernel.org>
> Closes: https://lore.kernel.org/20260516020430.110135-1-ojeda@kernel.org/
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Thanks, this fixes the warnings on 32-bit for me.

> --- a/drivers/hid/hid-core.c
> +++ b/drivers/hid/hid-core.c
> @@ -2050,7 +2050,7 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *
>                 return 0;
>
>         if (unlikely(bsize < csize)) {
> -               hid_warn_ratelimited(hid, "Event data for report %d is incorrect (%d vs %ld)\n",
> +               hid_warn_ratelimited(hid, "Event data for report %d is incorrect (%d vs %zu)\n",
>                                      report->id, csize, bsize);

Both report->id and csize are unsigned, so should use %u.

>                 return -EINVAL;
>         }
> @@ -2072,7 +2072,7 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *
>                 rsize = max_buffer_size;
>
>         if (bsize < rsize) {
> -               hid_warn_ratelimited(hid, "Event data for report %d was too short (%d vs %ld)\n",
> +               hid_warn_ratelimited(hid, "Event data for report %d was too short (%d vs %zu)\n",
>                                      report->id, rsize, bsize);

Same here.

>                 return -EINVAL;
>         }

And more incorrect %d outside the context!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] HID: core: Fix size_t specifier in hid_report_raw_event()
  2026-05-18  9:10 ` Geert Uytterhoeven
@ 2026-05-18 19:08   ` Nathan Chancellor
  0 siblings, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2026-05-18 19:08 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Jiri Kosina, Benjamin Tissoires, Greg Kroah-Hartman, Johan Hovold,
	linux-input, linux-kernel, stable, Miguel Ojeda

Hi Geert,

On Mon, May 18, 2026 at 11:10:49AM +0200, Geert Uytterhoeven wrote:
> On Sun, 17 May 2026 at 06:51, Nathan Chancellor <nathan@kernel.org> wrote:
> > --- a/drivers/hid/hid-core.c
> > +++ b/drivers/hid/hid-core.c
> > @@ -2050,7 +2050,7 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *
> >                 return 0;
> >
> >         if (unlikely(bsize < csize)) {
> > -               hid_warn_ratelimited(hid, "Event data for report %d is incorrect (%d vs %ld)\n",
> > +               hid_warn_ratelimited(hid, "Event data for report %d is incorrect (%d vs %zu)\n",
> >                                      report->id, csize, bsize);
> 
> Both report->id and csize are unsigned, so should use %u.
> 
> >                 return -EINVAL;
> >         }
> > @@ -2072,7 +2072,7 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *
> >                 rsize = max_buffer_size;
> >
> >         if (bsize < rsize) {
> > -               hid_warn_ratelimited(hid, "Event data for report %d was too short (%d vs %ld)\n",
> > +               hid_warn_ratelimited(hid, "Event data for report %d was too short (%d vs %zu)\n",
> >                                      report->id, rsize, bsize);
> 
> Same here.
> 
> >                 return -EINVAL;
> >         }
> 
> And more incorrect %d outside the context!

Yeah, I had noticed this as well but I decided to keep the patch
contained to only address the instances that the compiler warned about.
I do think this is worth addressing in a follow up patch, which either I
or the HID maintainers can do.

Thanks for the review!

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-05-18 19:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-17  4:51 [PATCH] HID: core: Fix size_t specifier in hid_report_raw_event() Nathan Chancellor
2026-05-18  9:10 ` Geert Uytterhoeven
2026-05-18 19:08   ` Nathan Chancellor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox