* [PATCH 1/2] iio: buffer: Save a few cycles in 'iio_scan_mask_set()'
@ 2021-07-14 11:14 Christophe JAILLET
2021-07-14 11:14 ` [PATCH 2/2] iio: buffer: Move a sanity check at the beginning of 'iio_scan_mask_set()' Christophe JAILLET
2021-07-17 16:58 ` [PATCH 1/2] iio: buffer: Save a few cycles in 'iio_scan_mask_set()' Jonathan Cameron
0 siblings, 2 replies; 4+ messages in thread
From: Christophe JAILLET @ 2021-07-14 11:14 UTC (permalink / raw)
To: jic23, lars; +Cc: linux-iio, linux-kernel, kernel-janitors, Christophe JAILLET
Use 'bitmap_alloc()' instead of 'bitmap_zalloc()' because the bitmap
is fully overridden by a 'bitmap_copy()' call just after its allocation.
While at it, fix the style of a NULL check.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/iio/industrialio-buffer.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index fdd623407b96..6d4776a7f002 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -354,8 +354,8 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev,
const unsigned long *mask;
unsigned long *trialmask;
- trialmask = bitmap_zalloc(indio_dev->masklength, GFP_KERNEL);
- if (trialmask == NULL)
+ trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL);
+ if (!trialmask)
return -ENOMEM;
if (!indio_dev->masklength) {
WARN(1, "Trying to set scanmask prior to registering buffer\n");
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] iio: buffer: Move a sanity check at the beginning of 'iio_scan_mask_set()'
2021-07-14 11:14 [PATCH 1/2] iio: buffer: Save a few cycles in 'iio_scan_mask_set()' Christophe JAILLET
@ 2021-07-14 11:14 ` Christophe JAILLET
2021-07-17 16:59 ` Jonathan Cameron
2021-07-17 16:58 ` [PATCH 1/2] iio: buffer: Save a few cycles in 'iio_scan_mask_set()' Jonathan Cameron
1 sibling, 1 reply; 4+ messages in thread
From: Christophe JAILLET @ 2021-07-14 11:14 UTC (permalink / raw)
To: jic23, lars; +Cc: linux-iio, linux-kernel, kernel-janitors, Christophe JAILLET
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>
---
drivers/iio/industrialio-buffer.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 6d4776a7f002..a95cc2da56be 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -354,13 +354,14 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev,
const unsigned long *mask;
unsigned long *trialmask;
- trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL);
- if (!trialmask)
- return -ENOMEM;
if (!indio_dev->masklength) {
WARN(1, "Trying to set scanmask prior to registering buffer\n");
- goto err_invalid_mask;
+ return -EINVAL;
}
+
+ trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL);
+ if (!trialmask)
+ return -ENOMEM;
bitmap_copy(trialmask, buffer->scan_mask, indio_dev->masklength);
set_bit(bit, trialmask);
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] iio: buffer: Save a few cycles in 'iio_scan_mask_set()'
2021-07-14 11:14 [PATCH 1/2] iio: buffer: Save a few cycles in 'iio_scan_mask_set()' Christophe JAILLET
2021-07-14 11:14 ` [PATCH 2/2] iio: buffer: Move a sanity check at the beginning of 'iio_scan_mask_set()' Christophe JAILLET
@ 2021-07-17 16:58 ` Jonathan Cameron
1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2021-07-17 16:58 UTC (permalink / raw)
To: Christophe JAILLET; +Cc: lars, linux-iio, linux-kernel, kernel-janitors
On Wed, 14 Jul 2021 13:14:41 +0200
Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:
> Use 'bitmap_alloc()' instead of 'bitmap_zalloc()' because the bitmap
> is fully overridden by a 'bitmap_copy()' call just after its allocation.
>
> While at it, fix the style of a NULL check.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders
to poke at it.
Thanks,
Jonathan
> ---
> drivers/iio/industrialio-buffer.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index fdd623407b96..6d4776a7f002 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -354,8 +354,8 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev,
> const unsigned long *mask;
> unsigned long *trialmask;
>
> - trialmask = bitmap_zalloc(indio_dev->masklength, GFP_KERNEL);
> - if (trialmask == NULL)
> + trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL);
> + if (!trialmask)
> return -ENOMEM;
> if (!indio_dev->masklength) {
> WARN(1, "Trying to set scanmask prior to registering buffer\n");
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] iio: buffer: Move a sanity check at the beginning of 'iio_scan_mask_set()'
2021-07-14 11:14 ` [PATCH 2/2] iio: buffer: Move a sanity check at the beginning of 'iio_scan_mask_set()' Christophe JAILLET
@ 2021-07-17 16:59 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2021-07-17 16:59 UTC (permalink / raw)
To: Christophe JAILLET; +Cc: lars, linux-iio, linux-kernel, kernel-janitors
On Wed, 14 Jul 2021 13:14:51 +0200
Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:
> 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.
Indeed this is silly. I'd guess result of code evolution, but perhaps
I was crazy in the first place :)
Applied,
Thanks,
Jonathan
>
> Shuffle code a bit to check 'masklength' before calling 'bitmap_alloc()'
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> drivers/iio/industrialio-buffer.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index 6d4776a7f002..a95cc2da56be 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -354,13 +354,14 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev,
> const unsigned long *mask;
> unsigned long *trialmask;
>
> - trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL);
> - if (!trialmask)
> - return -ENOMEM;
> if (!indio_dev->masklength) {
> WARN(1, "Trying to set scanmask prior to registering buffer\n");
> - goto err_invalid_mask;
> + return -EINVAL;
> }
> +
> + trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL);
> + if (!trialmask)
> + return -ENOMEM;
> bitmap_copy(trialmask, buffer->scan_mask, indio_dev->masklength);
> set_bit(bit, trialmask);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-07-17 16:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-14 11:14 [PATCH 1/2] iio: buffer: Save a few cycles in 'iio_scan_mask_set()' Christophe JAILLET
2021-07-14 11:14 ` [PATCH 2/2] iio: buffer: Move a sanity check at the beginning of 'iio_scan_mask_set()' Christophe JAILLET
2021-07-17 16:59 ` Jonathan Cameron
2021-07-17 16:58 ` [PATCH 1/2] iio: buffer: Save a few cycles in 'iio_scan_mask_set()' Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).