mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Himadri Pandya <himadrispandya@gmail.com>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	USB list <linux-usb@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 1/2] USB: serial: ch314: use usb_control_msg_recv() and usb_control_msg_send()
Date: Wed, 27 Oct 2021 15:37:46 +0200	[thread overview]
Message-ID: <YXlWKuuYVeSWXNXR@hovoldconsulting.com> (raw)
In-Reply-To: <CAOY-YVmtt4XTet4hU43nfD4pj2W008ab-VRhBMs-One4kpEEug@mail.gmail.com>

On Wed, Oct 27, 2021 at 03:28:42PM +0200, Himadri Pandya wrote:
> On Wed, Oct 27, 2021 at 3:04 PM Johan Hovold <johan@kernel.org> wrote:
> > On Fri, Oct 01, 2021 at 08:57:19AM +0200, Himadri Pandya wrote:

> > > @@ -287,23 +277,18 @@ static int ch341_set_handshake(struct usb_device *dev, u8 control)
> > >  static int ch341_get_status(struct usb_device *dev, struct ch341_private *priv)
> > >  {
> > >       const unsigned int size = 2;
> > > -     char *buffer;
> > > +     u8 buffer[2];
> > >       int r;
> > >       unsigned long flags;
> > >
> > > -     buffer = kmalloc(size, GFP_KERNEL);
> > > -     if (!buffer)
> > > -             return -ENOMEM;
> > > -
> > >       r = ch341_control_in(dev, CH341_REQ_READ_REG, 0x0706, 0, buffer, size);
> > > -     if (r < 0)
> > > -             goto out;
> > > +     if (r)
> > > +             return r;
> > >
> > >       spin_lock_irqsave(&priv->lock, flags);
> > >       priv->msr = (~(*buffer)) & CH341_BITS_MODEM_STAT;
> > >       spin_unlock_irqrestore(&priv->lock, flags);
> > >
> > > -out: kfree(buffer);
> > >       return r;
> >
> > This should now be
> >
> >         return 0;
> >
> 
> Yes. The function was returning the negative error value before the
> change. But now it doesn't need to as we are already taking care of it
> in the wrapper.

It has more to do with the fact that we now return early on errors so r
will always be zero here. It's better to be explicit about that.
 
> > >  }
> > >
> > > @@ -312,30 +297,25 @@ out:    kfree(buffer);
> > >  static int ch341_configure(struct usb_device *dev, struct ch341_private *priv)
> > >  {
> > >       const unsigned int size = 2;
> > > -     char *buffer;
> > > +     u8 buffer[2];
> > >       int r;
> > >
> > > -     buffer = kmalloc(size, GFP_KERNEL);
> > > -     if (!buffer)
> > > -             return -ENOMEM;
> > > -
> > >       /* expect two bytes 0x27 0x00 */
> > >       r = ch341_control_in(dev, CH341_REQ_READ_VERSION, 0, 0, buffer, size);
> > > -     if (r < 0)
> > > -             goto out;
> > > +     if (r)
> > > +             return r;
> > >       dev_dbg(&dev->dev, "Chip version: 0x%02x\n", buffer[0]);
> > >
> > >       r = ch341_control_out(dev, CH341_REQ_SERIAL_INIT, 0, 0);
> > > -     if (r < 0)
> > > -             goto out;
> > > +     if (r)
> > > +             return r;
> >
> > Now an unrelated change.
> 
> I think it is a related change because we are removing the out label.

Sorry, I meant that the (r < 0) change was unrelated since you're no
longer touching ch341_control_out(). The return is indeed still needed.
 
> > > @@ -647,23 +611,19 @@ static void ch341_break_ctl(struct tty_struct *tty, int break_state)
> > >       struct ch341_private *priv = usb_get_serial_port_data(port);
> > >       int r;
> > >       uint16_t reg_contents;
> > > -     uint8_t *break_reg;
> > > +     uint8_t break_reg[2];
> > >
> > >       if (priv->quirks & CH341_QUIRK_SIMULATE_BREAK) {
> > >               ch341_simulate_break(tty, break_state);
> > >               return;
> > >       }
> > >
> > > -     break_reg = kmalloc(2, GFP_KERNEL);
> > > -     if (!break_reg)
> > > -             return;
> > > -
> > >       r = ch341_control_in(port->serial->dev, CH341_REQ_READ_REG,
> > >                       ch341_break_reg, 0, break_reg, 2);
> > > -     if (r < 0) {
> > > +     if (r) {
> > >               dev_err(&port->dev, "%s - USB control read error (%d)\n",
> > >                               __func__, r);
> > > -             goto out;
> > > +             return;
> > >       }
> > >       dev_dbg(&port->dev, "%s - initial ch341 break register contents - reg1: %x, reg2: %x\n",
> > >               __func__, break_reg[0], break_reg[1]);
> > > @@ -681,11 +641,9 @@ static void ch341_break_ctl(struct tty_struct *tty, int break_state)
> > >       reg_contents = get_unaligned_le16(break_reg);
> > >       r = ch341_control_out(port->serial->dev, CH341_REQ_WRITE_REG,
> > >                       ch341_break_reg, reg_contents);
> > > -     if (r < 0)
> > > +     if (r)
> >
> > Now also an unrelated change.
> >
> 
> Maybe I misunderstood your comments on v2. I thought you asked to get
> rid of the out labels in callers.

Yes, but as above I'm referring to the (r < 0) change for
ch341_control_out() which is now unrelated to the rest of the patch.

Johan

  reply	other threads:[~2021-10-27 13:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01  6:57 [PATCH v3 0/2] USB: serial: use wrappers for usb_control_msg() Himadri Pandya
2021-10-01  6:57 ` [PATCH v3 1/2] USB: serial: ch314: use usb_control_msg_recv() and usb_control_msg_send() Himadri Pandya
2021-10-27 13:04   ` Johan Hovold
2021-10-27 13:28     ` Himadri Pandya
2021-10-27 13:37       ` Johan Hovold [this message]
2021-10-27 13:47         ` Himadri Pandya
2021-10-01  6:57 ` [PATCH v3 2/2] USB: serial: cp210x: " Himadri Pandya
2021-10-27 13:17   ` Johan Hovold
2021-10-27 13:34     ` 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:
  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=YXlWKuuYVeSWXNXR@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=himadrispandya@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.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

Powered by JetHome