Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: buffer: Move a sanity check at the beginning of 'iio_scan_mask_set()'

This is more standard to have sanity checks at the entry of a function,
instead of allocating some memory first and having to free it if a
condition is not met.

Shuffle code a bit to check 'masklength' before calling 'bitmap_alloc()'

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/98a351adda1908c306e981b9cc86d3dbc79eb5ec.1626261211.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Christophe JAILLET and committed by
Jonathan Cameron
d21fed06 45851650

+5 -4
+5 -4
drivers/iio/industrialio-buffer.c
··· 354 354 const unsigned long *mask; 355 355 unsigned long *trialmask; 356 356 357 + if (!indio_dev->masklength) { 358 + WARN(1, "Trying to set scanmask prior to registering buffer\n"); 359 + return -EINVAL; 360 + } 361 + 357 362 trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL); 358 363 if (!trialmask) 359 364 return -ENOMEM; 360 - if (!indio_dev->masklength) { 361 - WARN(1, "Trying to set scanmask prior to registering buffer\n"); 362 - goto err_invalid_mask; 363 - } 364 365 bitmap_copy(trialmask, buffer->scan_mask, indio_dev->masklength); 365 366 set_bit(bit, trialmask); 366 367