diff mbox series

iio: Fix scan mask selection

Message ID 20190220141403.11571-1-alexandru.ardelean@analog.com (mailing list archive)
State New, archived
Headers show
Series iio: Fix scan mask selection | expand

Commit Message

Alexandru Ardelean Feb. 20, 2019, 2:14 p.m. UTC
From: Lars-Peter Clausen <lars@metafoo.de>

The trialmask is expected to have all bits set to 0 after allocation.
Currently kmalloc_array() is used which does not zero the memory and so
random bits are set. This results in random channels being enabled when
they shouldn't. Replace kmalloc_array() with kcalloc() which has the same
interface but zeros the memory.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/industrialio-buffer.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Alexandru Ardelean Feb. 20, 2019, 3:09 p.m. UTC | #1
On Wed, 2019-02-20 at 16:14 +0200, Alexandru Ardelean wrote:
> From: Lars-Peter Clausen <lars@metafoo.de>

I'll send a V2 with the Fixes tag.

> 
> The trialmask is expected to have all bits set to 0 after allocation.
> Currently kmalloc_array() is used which does not zero the memory and so
> random bits are set. This results in random channels being enabled when
> they shouldn't. Replace kmalloc_array() with kcalloc() which has the same
> interface but zeros the memory.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> ---
>  drivers/iio/industrialio-buffer.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-buffer.c
> b/drivers/iio/industrialio-buffer.c
> index cd5bfe39591b..dadd921a4a30 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -320,9 +320,8 @@ static int iio_scan_mask_set(struct iio_dev
> *indio_dev,
>  	const unsigned long *mask;
>  	unsigned long *trialmask;
>  
> -	trialmask = kmalloc_array(BITS_TO_LONGS(indio_dev->masklength),
> -				  sizeof(*trialmask),
> -				  GFP_KERNEL);
> +	trialmask = kcalloc(BITS_TO_LONGS(indio_dev->masklength),
> +			    sizeof(*trialmask), GFP_KERNEL);
>  	if (trialmask == NULL)
>  		return -ENOMEM;
>  	if (!indio_dev->masklength) {
diff mbox series

Patch

diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index cd5bfe39591b..dadd921a4a30 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -320,9 +320,8 @@  static int iio_scan_mask_set(struct iio_dev *indio_dev,
 	const unsigned long *mask;
 	unsigned long *trialmask;
 
-	trialmask = kmalloc_array(BITS_TO_LONGS(indio_dev->masklength),
-				  sizeof(*trialmask),
-				  GFP_KERNEL);
+	trialmask = kcalloc(BITS_TO_LONGS(indio_dev->masklength),
+			    sizeof(*trialmask), GFP_KERNEL);
 	if (trialmask == NULL)
 		return -ENOMEM;
 	if (!indio_dev->masklength) {