mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: 陳偉銘 <jj251510319013@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	balbi@kernel.org, "Maciej Żenczykowski" <maze@google.com>
Subject: Re: [PATCH] usb: gadget: function: Fix returning incorrect PNP string
Date: Wed, 26 Jan 2022 13:21:31 +0100	[thread overview]
Message-ID: <YfE8y8xpJIwC8Ojo@kroah.com> (raw)
In-Reply-To: <CAJwFiG+caDOp48R+EMATi9W_hCt-SBoEeeeEK8XGuRWai=bYug@mail.gmail.com>

On Fri, Jan 07, 2022 at 10:37:19AM +0800, 陳偉銘 wrote:
> Greg KH <gregkh@linuxfoundation.org> 於 2022年1月6日 週四 下午10:35寫道:
> >
> > On Wed, Jan 05, 2022 at 12:04:39PM +0800, Wei Ming Chen wrote:
> > > There will be 2 leading bytes indicating the total length of
> > > the PNP string, so I think we should add value by 2, otherwise
> > > the PNP string copied to user will not contain the last 2 bytes
> > >
> > > Signed-off-by: Wei Ming Chen <jj251510319013@gmail.com>
> > > ---
> > >  drivers/usb/gadget/function/f_printer.c | 4 +++-
> > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c
> > > index abec5c58f525..3fb00fd0b5ee 100644
> > > --- a/drivers/usb/gadget/function/f_printer.c
> > > +++ b/drivers/usb/gadget/function/f_printer.c
> > > @@ -1005,9 +1005,11 @@ static int printer_func_setup(struct usb_function *f,
> > >                               break;
> > >                       }
> > >                       value = strlen(dev->pnp_string);
> > > +                     memcpy(buf + 2, dev->pnp_string, value);
> > > +
> > > +                     value += 2;
> > >                       buf[0] = (value >> 8) & 0xFF;
> > >                       buf[1] = value & 0xFF;
> > > -                     memcpy(buf + 2, dev->pnp_string, value);
> > >                       DBG(dev, "1284 PNP String: %x %s\n", value,
> > >                           dev->pnp_string);
> > >                       break;
> > > --
> > > 2.25.1
> > >
> >
> > Are you sure this is correct?
> >
> > How is this related to this recent thread:
> >         https://lore.kernel.org/all/CAKjGFBUdjXcZoVV4jdrgTz4rKThTfZAK4CqreKmBZ4KHE+K1GA@mail.gmail.com/#t
> >
> > your change is different from what is proposed there, why?
> 
> I didn’t notice this thread before I send this patch, I think the
> concept of my change is similar to Volodymyr Lisivka’s change, he/she
> introduced a separate variable for the PNP string length, I think it
> may be clearer and more readable than just “value += 2”
> 
> 
> Another thing that I am not too sure whether I am correct is this line of code
> 
> DBG(dev, "1284 PNP String: %x %s\n", value,
>                              dev->pnp_string);
> 
> What Volodymyr Lisivka changed is like this
> 
> DBG(dev, "1284 PNP String: %x %s\n", pnp_length,
>                              dev->pnp_string);
> 
> In my change, “value” equals to “pnp_length + 2” in Volodymyr
> Lisivka’s change, and I think we should print “the PNP string length +
> 2” instead of “the PNP string length”?
> 

I do not know, I suggest you two work together to get the correct fix
submitted.

thanks,

greg k-h

      reply	other threads:[~2022-01-26 12:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-05  4:04 Wei Ming Chen
2022-01-06 14:35 ` Greg KH
2022-01-07  2:37   ` 陳偉銘
2022-01-26 12:21     ` Greg KH [this message]

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=YfE8y8xpJIwC8Ojo@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=balbi@kernel.org \
    --cc=jj251510319013@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=maze@google.com \
    /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

Powered by JetHome