lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <8df8a0d7d541b1f4f2a05f1191a148d3b56effe6.camel@analog.com>
Date:   Sat, 18 Apr 2020 16:28:35 +0000
From:   "Ardelean, Alexandru" <alexandru.Ardelean@...log.com>
To:     "jic23@...nel.org" <jic23@...nel.org>
CC:     "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "linux-iio@...r.kernel.org" <linux-iio@...r.kernel.org>
Subject: Re: [PATCH] iio: core: fail early in iio_device_alloc() if we can't
 get a device id

On Sat, 2020-04-18 at 16:25 +0100, Jonathan Cameron wrote:
> [External]
> 
> On Thu, 16 Apr 2020 15:33:31 +0300
> Alexandru Ardelean <alexandru.ardelean@...log.com> wrote:
> 
> > This change moves the 'ida_simple_get()' call to be the first one in
> > iio_device_alloc(). It cleans up the error path a bit as we don't need to
> > call any kfree(dev) anymore. We allocate an IIO device only if we have
> > managed to obtain a device ID.
> 
> We just threw away an ID if the kzalloc then fails (or am I missing
> something?)
> With that fixed I can't see this as being much of an improvement.
> Either way one allocation needs to be tidied up.

oops,
the ida thingi eluded me when i wrote this;
apologies for the noise


> 
> Jonathan
> 
> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@...log.com>
> > ---
> >  drivers/iio/industrialio-core.c | 19 ++++++++++---------
> >  1 file changed, 10 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-
> > core.c
> > index f4daf19f2a3b..7c1d8a3ab2f3 100644
> > --- a/drivers/iio/industrialio-core.c
> > +++ b/drivers/iio/industrialio-core.c
> > @@ -1494,6 +1494,14 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
> >  {
> >  	struct iio_dev *dev;
> >  	size_t alloc_size;
> > +	int id;
> > +
> > +	id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
> > +	if (id < 0) {
> > +		/* cannot use a dev_err as the name isn't available */
> > +		pr_err("failed to get device id\n");
> > +		return NULL;
> > +	}
> >  
> >  	alloc_size = sizeof(struct iio_dev);
> >  	if (sizeof_priv) {
> > @@ -1506,6 +1514,8 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
> >  	dev = kzalloc(alloc_size, GFP_KERNEL);
> >  
> >  	if (dev) {
> > +		dev->id = id;
> > +		dev_set_name(&dev->dev, "iio:device%d", dev->id);
> >  		dev->dev.groups = dev->groups;
> >  		dev->dev.type = &iio_device_type;
> >  		dev->dev.bus = &iio_bus_type;
> > @@ -1514,15 +1524,6 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
> >  		mutex_init(&dev->mlock);
> >  		mutex_init(&dev->info_exist_lock);
> >  		INIT_LIST_HEAD(&dev->channel_attr_list);
> > -
> > -		dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
> > -		if (dev->id < 0) {
> > -			/* cannot use a dev_err as the name isn't available */
> > -			pr_err("failed to get device id\n");
> > -			kfree(dev);
> > -			return NULL;
> > -		}
> > -		dev_set_name(&dev->dev, "iio:device%d", dev->id);
> >  		INIT_LIST_HEAD(&dev->buffer_list);
> >  	}
> >  

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ