All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Lucas Tanure <tanure@linux.com>
Cc: Bastien Nocera <hadess@hadess.net>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] USB: apple-mfi-fastcharge: Use devm_kzalloc and simplify the code
Date: Sun, 15 Nov 2020 09:26:58 +0100	[thread overview]
Message-ID: <X7DmUsasFnylaY8C@kroah.com> (raw)
In-Reply-To: <CAJX_Q+0-9=7q=VcM6uP+8mCX2mVAjS4sT52mvpj-hS6rm63DGg@mail.gmail.com>

On Sun, Nov 15, 2020 at 08:13:51AM +0000, Lucas Tanure wrote:
> On Sat, Nov 14, 2020 at 3:03 PM Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> wrote:
> >
> > On Sat, Nov 14, 2020 at 02:17:48PM +0000, Lucas Tanure wrote:
> > > On Sat, Nov 14, 2020 at 12:56 PM Greg Kroah-Hartman
> > > <gregkh@linuxfoundation.org> wrote:
> > > >
> > > > On Sat, Nov 14, 2020 at 12:42:49PM +0000, Lucas Tanure wrote:
> > > > > Signed-off-by: Lucas Tanure <tanure@linux.com>
> > > >
> > > > I can't take patches without any changelog text, sorry.
> > > >
> > > > > ---
> > > > >  drivers/usb/misc/apple-mfi-fastcharge.c | 17 +++++------------
> > > > >  1 file changed, 5 insertions(+), 12 deletions(-)
> > > > >
> > > > > diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/apple-mfi-fastcharge.c
> > > > > index 9de0171b5177..de86e389a008 100644
> > > > > --- a/drivers/usb/misc/apple-mfi-fastcharge.c
> > > > > +++ b/drivers/usb/misc/apple-mfi-fastcharge.c
> > > > > @@ -178,16 +178,13 @@ static int mfi_fc_probe(struct usb_device *udev)
> > > > >  {
> > > > >       struct power_supply_config battery_cfg = {};
> > > > >       struct mfi_device *mfi = NULL;
> > > > > -     int err;
> > > > >
> > > > >       if (!mfi_fc_match(udev))
> > > > >               return -ENODEV;
> > > > >
> > > > > -     mfi = kzalloc(sizeof(struct mfi_device), GFP_KERNEL);
> > > > > -     if (!mfi) {
> > > > > -             err = -ENOMEM;
> > > > > -             goto error;
> > > > > -     }
> > > > > +     mfi = devm_kzalloc(&udev->dev, sizeof(*mfi), GFP_KERNEL);
> > > > > +     if (!mfi)
> > > > > +             return -ENOMEM;
> > > > >
> > > > >       battery_cfg.drv_data = mfi;
> > > > >
> > > > > @@ -197,8 +194,7 @@ static int mfi_fc_probe(struct usb_device *udev)
> > > > >                                               &battery_cfg);
> > > > >       if (IS_ERR(mfi->battery)) {
> > > > >               dev_err(&udev->dev, "Can't register battery\n");
> > > > > -             err = PTR_ERR(mfi->battery);
> > > > > -             goto error;
> > > > > +             return PTR_ERR(mfi->battery);
> > > > >       }
> > > > >
> > > > >       mfi->udev = usb_get_dev(udev);
> > > > > @@ -206,9 +202,6 @@ static int mfi_fc_probe(struct usb_device *udev)
> > > > >
> > > > >       return 0;
> > > > >
> > > > > -error:
> > > > > -     kfree(mfi);
> > > > > -     return err;
> > > > >  }
> > > > >
> > > > >  static void mfi_fc_disconnect(struct usb_device *udev)
> > > > > @@ -220,7 +213,7 @@ static void mfi_fc_disconnect(struct usb_device *udev)
> > > > >               power_supply_unregister(mfi->battery);
> > > > >       dev_set_drvdata(&udev->dev, NULL);
> > > > >       usb_put_dev(mfi->udev);
> > > > > -     kfree(mfi);
> > > > > +     devm_kfree(&udev->dev, mfi);
> > > >
> > > > Are you sure about this?
> > > I think so, as the probe will allocate again that struct, the
> > > disconnect should free the previous one.
> >
> > Why do you need to manually free it here like this?
> My understanding is that memory will only be freed when the driver
> gets unloaded and the next connection of the device will allocate a
> new one.
> So every new disconnection and re-connection there will be a small
> memory leak until the driver gets unloaded.

devm_* functions operate on the lifecycle of the device, not the driver.
Two totally different things :)

> > Why are you trying to convert this file to this api anyway?
> I was just trying to improve the code as the original source calls
> kfree even when kzalloc fails.

Then please fix that bug independant of any conversion to a new api, as
that is a bugfix that should be backported to older kernels.

> And using devm_* would remove the need for kfree and the end of probe.

Yes, but you can't introduce new bugs when trying to fix existing ones.

Also, you didn't say this was a bugfix anywhere, which is one reason
that writing good changelog text is essencial.

thanks,

greg k-h

      reply	other threads:[~2020-11-15  8:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-14 12:42 [PATCH] USB: apple-mfi-fastcharge: Use devm_kzalloc and simplify the code Lucas Tanure
2020-11-14 12:56 ` Greg Kroah-Hartman
2020-11-14 14:17   ` Lucas Tanure
2020-11-14 15:02     ` Greg Kroah-Hartman
2020-11-15  8:13       ` Lucas Tanure
2020-11-15  8:26         ` Greg Kroah-Hartman [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=X7DmUsasFnylaY8C@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=hadess@hadess.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=tanure@linux.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.