All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: kbuild@lists.01.org, Drew Fustini <drew@beagleboard.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Tony Lindgren <tony@atomide.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Pantelis Antoniou <pantelis.antoniou@konsulko.com>,
	Jason Kridner <jkridner@beagleboard.org>,
	Robert Nelson <robertcnelson@beagleboard.org>,
	kbuild test robot <lkp@intel.com>,
	kbuild-all@lists.01.org
Subject: Re: [PATCH v2 2/2] pinctrl: pinmux: Add pinmux-select debugfs file
Date: Wed, 10 Feb 2021 22:05:29 +0300	[thread overview]
Message-ID: <20210210190528.GE20820@kadam> (raw)
In-Reply-To: <CAMuHMdUTG-0PMsP--i4KE2RA_zOaQgpUDksvtU8dLPW9dSpoug@mail.gmail.com>

On Wed, Feb 10, 2021 at 07:39:16PM +0100, Geert Uytterhoeven wrote:
> Hi Dan,
> 
> On Wed, Feb 10, 2021 at 7:21 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  694    buf = devm_kzalloc(pctldev->dev, PINMUX_MAX_NAME * 2, GFP_KERNEL);
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  695    if (!buf)
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  696            return -ENOMEM;
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  697
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  698    fname = devm_kzalloc(pctldev->dev, PINMUX_MAX_NAME, GFP_KERNEL);
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  699    if (!fname) {
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  700            ret = -ENOMEM;
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  701            goto free_buf;
> >
> > The gotos are out of order.  They should be in mirror/reverse order of
> > the allocations:
> >
> > free_gmane:
> >         devm_kfree(pctldev->dev, gname);
> > free_fname:
> >         devm_kfree(pctldev->dev, fname);
> > free_buf:
> >         devm_kfree(pctldev->dev, buf);
> >
> > But also why do we need to use devm_kfree() at all?  I thought the whole
> > point of devm_ functions was that they are garbage collected
> > automatically for you.  Can we not just delete all error handling and
> > return -ENOMEM here?
> 
> No, because the lifetime of the objects allocated here does not match the
> lifetime of dev.  If they're not freed here, they will only be freed when the
> device is unbound.  As the user can access the sysfs files at will, he can
> OOM the system.
> 

Then why not use vanilla kmalloc()?

regards,
dan carpenter


WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org
Subject: Re: [PATCH v2 2/2] pinctrl: pinmux: Add pinmux-select debugfs file
Date: Wed, 10 Feb 2021 22:05:29 +0300	[thread overview]
Message-ID: <20210210190528.GE20820@kadam> (raw)
In-Reply-To: <CAMuHMdUTG-0PMsP--i4KE2RA_zOaQgpUDksvtU8dLPW9dSpoug@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1686 bytes --]

On Wed, Feb 10, 2021 at 07:39:16PM +0100, Geert Uytterhoeven wrote:
> Hi Dan,
> 
> On Wed, Feb 10, 2021 at 7:21 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  694    buf = devm_kzalloc(pctldev->dev, PINMUX_MAX_NAME * 2, GFP_KERNEL);
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  695    if (!buf)
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  696            return -ENOMEM;
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  697
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  698    fname = devm_kzalloc(pctldev->dev, PINMUX_MAX_NAME, GFP_KERNEL);
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  699    if (!fname) {
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  700            ret = -ENOMEM;
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  701            goto free_buf;
> >
> > The gotos are out of order.  They should be in mirror/reverse order of
> > the allocations:
> >
> > free_gmane:
> >         devm_kfree(pctldev->dev, gname);
> > free_fname:
> >         devm_kfree(pctldev->dev, fname);
> > free_buf:
> >         devm_kfree(pctldev->dev, buf);
> >
> > But also why do we need to use devm_kfree() at all?  I thought the whole
> > point of devm_ functions was that they are garbage collected
> > automatically for you.  Can we not just delete all error handling and
> > return -ENOMEM here?
> 
> No, because the lifetime of the objects allocated here does not match the
> lifetime of dev.  If they're not freed here, they will only be freed when the
> device is unbound.  As the user can access the sysfs files at will, he can
> OOM the system.
> 

Then why not use vanilla kmalloc()?

regards,
dan carpenter

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild-all@lists.01.org
Subject: Re: [PATCH v2 2/2] pinctrl: pinmux: Add pinmux-select debugfs file
Date: Wed, 10 Feb 2021 22:05:29 +0300	[thread overview]
Message-ID: <20210210190528.GE20820@kadam> (raw)
In-Reply-To: <CAMuHMdUTG-0PMsP--i4KE2RA_zOaQgpUDksvtU8dLPW9dSpoug@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1686 bytes --]

On Wed, Feb 10, 2021 at 07:39:16PM +0100, Geert Uytterhoeven wrote:
> Hi Dan,
> 
> On Wed, Feb 10, 2021 at 7:21 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  694    buf = devm_kzalloc(pctldev->dev, PINMUX_MAX_NAME * 2, GFP_KERNEL);
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  695    if (!buf)
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  696            return -ENOMEM;
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  697
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  698    fname = devm_kzalloc(pctldev->dev, PINMUX_MAX_NAME, GFP_KERNEL);
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  699    if (!fname) {
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  700            ret = -ENOMEM;
> > 99b2f99aa41aa7 Drew Fustini  2021-02-09  701            goto free_buf;
> >
> > The gotos are out of order.  They should be in mirror/reverse order of
> > the allocations:
> >
> > free_gmane:
> >         devm_kfree(pctldev->dev, gname);
> > free_fname:
> >         devm_kfree(pctldev->dev, fname);
> > free_buf:
> >         devm_kfree(pctldev->dev, buf);
> >
> > But also why do we need to use devm_kfree() at all?  I thought the whole
> > point of devm_ functions was that they are garbage collected
> > automatically for you.  Can we not just delete all error handling and
> > return -ENOMEM here?
> 
> No, because the lifetime of the objects allocated here does not match the
> lifetime of dev.  If they're not freed here, they will only be freed when the
> device is unbound.  As the user can access the sysfs files at will, he can
> OOM the system.
> 

Then why not use vanilla kmalloc()?

regards,
dan carpenter

  reply	other threads:[~2021-02-10 19:07 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-10  7:49 [PATCH v2 0/2] pinctrl: pinmux: Add pinmux-select debugfs file Drew Fustini
2021-02-10  7:49 ` [PATCH v2 1/2] pinctrl: use to octal permissions for debugfs files Drew Fustini
2021-02-10  8:30   ` Joe Perches
2021-02-10 10:18     ` Andy Shevchenko
2021-02-10 12:36       ` Joe Perches
2021-02-10 21:21         ` Drew Fustini
2021-02-10 23:12           ` Joe Perches
2021-02-10  8:31   ` Geert Uytterhoeven
2021-02-10 10:14     ` Andy Shevchenko
2021-02-10 10:16   ` Andy Shevchenko
2021-02-10  7:49 ` [PATCH v2 2/2] pinctrl: pinmux: Add pinmux-select debugfs file Drew Fustini
2021-02-10  8:35   ` Geert Uytterhoeven
2021-02-10  9:56   ` Andy Shevchenko
2021-02-10 17:31     ` Drew Fustini
2021-02-10 18:20   ` Dan Carpenter
2021-02-10 18:20     ` Dan Carpenter
2021-02-10 18:20     ` Dan Carpenter
2021-02-10 18:39     ` Geert Uytterhoeven
2021-02-10 18:39       ` Geert Uytterhoeven
2021-02-10 19:05       ` Dan Carpenter [this message]
2021-02-10 19:05         ` Dan Carpenter
2021-02-10 19:05         ` Dan Carpenter
2021-02-10 19:14         ` Drew Fustini
2021-02-10 19:04     ` Drew Fustini
2021-02-10 20:33       ` Dan Carpenter
2021-02-10 20:33         ` Dan Carpenter
2021-02-10 20:33         ` Dan Carpenter
2021-02-10 15:29 kernel test robot

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=20210210190528.GE20820@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=drew@beagleboard.org \
    --cc=geert@linux-m68k.org \
    --cc=jkridner@beagleboard.org \
    --cc=kbuild-all@lists.01.org \
    --cc=kbuild@lists.01.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=pantelis.antoniou@konsulko.com \
    --cc=robertcnelson@beagleboard.org \
    --cc=tony@atomide.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.