archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <>
To: Dmitry Vyukov <>
Cc: netdev <>,
	USB list <>,
	syzkaller-bugs <>,
	LKML <>,
	Jakub Kicinski <>,,
	David Miller <>,
	Himadri Pandya <>
Subject: Re: [Linux-kernel-mentees] [PATCH] net: usb: Fix uninit-was-stored issue in asix_read_cmd()
Date: Sun, 23 Aug 2020 12:56:22 +0200	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

On Sun, Aug 23, 2020 at 12:31:03PM +0200, Dmitry Vyukov wrote:
> On Sun, Aug 23, 2020 at 12:19 PM Greg Kroah-Hartman
> > It's not always a failure, some devices have protocols that are "I could
> > return up to a max X bytes but could be shorter" types of messages, so
> > it's up to the caller to check that they got what they really asked for.
> Yes, that's why I said _separate_ helper function. There seems to be
> lots of callers that want exactly this -- "I want 4 bytes, anything
> else is an error". With the current API it's harder to do - you need
> additional checks, additional code, maybe even additional variables to
> store the required size. APIs should make correct code easy to write.

One note on this, will respond to the rest of the email later.

It should be the same exact amount of code in the driver to handle this
either way:

Today's correctly written driver:

	data_size = 4;
	data = kmalloc(data_size, GFP_KERNEL);

	retval = usb_control_msg(....., data, data_size, ...);
	if (retval < buf_size) {

With your new function:

	data_size = 4;
	data = kmalloc(data_size, GFP_KERNEL);

	retval = usb_control_msg_error_on_short(....., data, data_size, ...);
	if (retval < 0) {

Catch the difference, it's only in checking for retval, either way you
are writing the exact same logic in the driver, you still have to tell
the USB layer the size of the buffer you want to read into, still have
to pass in the buffer, and everything else.  You already know the size
of the data you want, and you already are doing the check, those things
you have to do no matter what, it's not extra work.

We can write a wrapper around usb_control_msg() for something like this
that does the transformation of a short read into an error, but really,
does that give us all that much here?

Yes, I want to make it easy to write correct drivers, and hard to get
things wrong, but in this case, I don't see the new way any "harder" to
get wrong.

Unless you know of a simpler way here?


greg k-h
Linux-kernel-mentees mailing list

  reply	other threads:[~2020-08-23 10:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-23  8:20 [Linux-kernel-mentees] [PATCH] net: usb: Fix uninit-was-stored issue in asix_read_cmd() Himadri Pandya
2020-08-23  9:26 ` Dmitry Vyukov via Linux-kernel-mentees
2020-08-23 10:19   ` Greg Kroah-Hartman
2020-08-23 10:31     ` Dmitry Vyukov via Linux-kernel-mentees
2020-08-23 10:56       ` Greg Kroah-Hartman [this message]
2020-08-23 10:58       ` Greg Kroah-Hartman
2020-08-23 12:38         ` Himadri Pandya
2020-08-24  8:55         ` Dmitry Vyukov via Linux-kernel-mentees
2020-08-25  6:51           ` Greg Kroah-Hartman
2020-08-25  6:54             ` Greg Kroah-Hartman
2020-08-25 14:39             ` Alan Stern
2020-08-25 14:44               ` Greg Kroah-Hartman
2020-08-25 15:44                 ` Greg Kroah-Hartman
2020-08-24 18:16 ` Jakub Kicinski
2020-08-25  6:36   ` Himadri Pandya

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \

* 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).