Re: [PATCH v2 2/2] pinctrl: pinmux: Add pinmux-select debugfs file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 10, 2021 at 11:56:49AM +0200, Andy Shevchenko wrote:
> On Wed, Feb 10, 2021 at 9:50 AM Drew Fustini <drew@xxxxxxxxxxxxxxx> wrote:
> >
> > Add "pinmux-select" to debugfs which will activate a function and group
> > when 2 integers "<function-selector> <group-selector>" are written to
> > the file. The write operation pinmux_select() handles this by checking
> > if fsel and gsel are valid selectors and then calling ops->set_mux().
> >
> > The existing "pinmux-functions" debugfs file lists the pin functions
> > registered for the pin controller. For example:
> >
> > function: pinmux-uart0, groups = [ pinmux-uart0-pins ]
> > function: pinmux-mmc0, groups = [ pinmux-mmc0-pins ]
> > function: pinmux-mmc1, groups = [ pinmux-mmc1-pins ]
> > function: pinmux-i2c0, groups = [ pinmux-i2c0-pins ]
> > function: pinmux-i2c1, groups = [ pinmux-i2c1-pins ]
> > function: pinmux-spi1, groups = [ pinmux-spi1-pins ]
> >
> > To activate function pinmux-i2c1 (fsel 4) and group pinmux-i2c1-pins
> > (gsel 4):
> >
> > echo '4 4' > pinmux-select
> 
> ...
> 
> >  DEFINE_SHOW_ATTRIBUTE(pinmux_pins);
> >
> 
> > +
> 
> One blank line (existed) is enough.
> 
> > +#define PINMUX_MAX_NAME 64
> 
> ...
> 
> > +       buf = devm_kzalloc(pctldev->dev, PINMUX_MAX_NAME * 2, GFP_KERNEL);
> 
> You have to (re-)read documentation about Device Managed Resources.
> Keyword here is *device*! Pay attention to it. TL;DR: misuse of device
> managed resources here.
> Potentially memory exhausting (local DoS attack), but see below.
> 
> > +       if (!buf)
> > +               return -ENOMEM;
> 
> ...
> 
> > +       devm_kfree(pctldev->dev, buf);
> 
> Calling devm_kfree() or other devm_*() release kinda APIs is a red
> flag in 99%. See above.

Thank you for reviewing and pointing out this issue.

Do you mean that I should not be treating these buffers used in the 
debugfs write op as belonging to the pin controller device?

I have looked through the kernel code and I realize now that I don't see
any instances of devm_*() being used inside the read or write op for a
debugfs file. As I consider it further, devm_*() does not seem to make
sense as I am creating the buffers only for temporary use inside
pinmux_select().

I'll get that fixed in v3.

Thank you,
Drew



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux