提交 c354c295 编写于 作者: A Andy Shevchenko 提交者: Bartosz Golaszewski

gpiolib: Switch to bitmap_alloc()

Switch to bitmap_alloc() to show clearly what we are allocating.
Besides that it returns pointer of bitmap type instead of opaque void *.
Signed-off-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: NLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: NBartosz Golaszewski <bgolaszewski@baylibre.com>
上级 c80c4435
...@@ -2549,13 +2549,17 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep, ...@@ -2549,13 +2549,17 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep,
mask = fastpath_mask; mask = fastpath_mask;
bits = fastpath_bits; bits = fastpath_bits;
} else { } else {
mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio), gfp_t flags = can_sleep ? GFP_KERNEL : GFP_ATOMIC;
sizeof(*mask),
can_sleep ? GFP_KERNEL : GFP_ATOMIC); mask = bitmap_alloc(gc->ngpio, flags);
if (!mask) if (!mask)
return -ENOMEM; return -ENOMEM;
bits = mask + BITS_TO_LONGS(gc->ngpio); bits = bitmap_alloc(gc->ngpio, flags);
if (!bits) {
bitmap_free(mask);
return -ENOMEM;
}
} }
bitmap_zero(mask, gc->ngpio); bitmap_zero(mask, gc->ngpio);
...@@ -2581,7 +2585,9 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep, ...@@ -2581,7 +2585,9 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep,
ret = gpio_chip_get_multiple(gc, mask, bits); ret = gpio_chip_get_multiple(gc, mask, bits);
if (ret) { if (ret) {
if (mask != fastpath_mask) if (mask != fastpath_mask)
kfree(mask); bitmap_free(mask);
if (bits != fastpath_bits)
bitmap_free(bits);
return ret; return ret;
} }
...@@ -2602,7 +2608,9 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep, ...@@ -2602,7 +2608,9 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep,
} }
if (mask != fastpath_mask) if (mask != fastpath_mask)
kfree(mask); bitmap_free(mask);
if (bits != fastpath_bits)
bitmap_free(bits);
} }
return 0; return 0;
} }
...@@ -2835,13 +2843,17 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep, ...@@ -2835,13 +2843,17 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
mask = fastpath_mask; mask = fastpath_mask;
bits = fastpath_bits; bits = fastpath_bits;
} else { } else {
mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio), gfp_t flags = can_sleep ? GFP_KERNEL : GFP_ATOMIC;
sizeof(*mask),
can_sleep ? GFP_KERNEL : GFP_ATOMIC); mask = bitmap_alloc(gc->ngpio, flags);
if (!mask) if (!mask)
return -ENOMEM; return -ENOMEM;
bits = mask + BITS_TO_LONGS(gc->ngpio); bits = bitmap_alloc(gc->ngpio, flags);
if (!bits) {
bitmap_free(mask);
return -ENOMEM;
}
} }
bitmap_zero(mask, gc->ngpio); bitmap_zero(mask, gc->ngpio);
...@@ -2889,7 +2901,9 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep, ...@@ -2889,7 +2901,9 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
gpio_chip_set_multiple(gc, mask, bits); gpio_chip_set_multiple(gc, mask, bits);
if (mask != fastpath_mask) if (mask != fastpath_mask)
kfree(mask); bitmap_free(mask);
if (bits != fastpath_bits)
bitmap_free(bits);
} }
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册