iio: Fix scan mask selection [Linux 3.16.72]

This Linux kernel change "iio: Fix scan mask selection" is included in the Linux 3.16.72 release. This change is authored by Lars-Peter Clausen <lars [at] metafoo.de> on Wed Feb 20 17:11:32 2019 +0200. The commit for this change in Linux stable tree is f7803d7 (patch) which is from upstream commit 20ea39e. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 20ea39e.

iio: Fix scan mask selection

commit 20ea39ef9f2f911bd01c69519e7d69cfec79fde3 upstream.

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.

Note the fix is actually required earlier than the below fixes tag, but
will require a manual backport due to move from kmalloc to kmalloc_array.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Fixes commit 057ac1acdfc4 ("iio: Use kmalloc_array() in iio_scan_mask_set()").
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

There are 5 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 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 7613668..77b19ca 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -836,9 +836,8 @@ 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) {

Leave a Reply

Your email address will not be published. Required fields are marked *