2021-04-09 09:44:06

by yebin (H)

[permalink] [raw]
Subject: [PATCH -next] char: xilinx_hwicap: use DEFINE_MUTEX() for mutex lock

mutex lock can be initialized automatically with DEFINE_MUTEX()
rather than explicitly calling mutex_init().

Reported-by: Hulk Robot <[email protected]>
Signed-off-by: Ye Bin <[email protected]>
---
drivers/char/xilinx_hwicap/xilinx_hwicap.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
index 067396bedf22..4d586233dfa4 100644
--- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
+++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
@@ -111,7 +111,7 @@
/* An array, which is set to true when the device is registered. */
static DEFINE_MUTEX(hwicap_mutex);
static bool probed_devices[HWICAP_DEVICES];
-static struct mutex icap_sem;
+static DEFINE_MUTEX(icap_sem);

static struct class *icap_class;

@@ -857,7 +857,6 @@ static int __init hwicap_module_init(void)
int retval;

icap_class = class_create(THIS_MODULE, "xilinx_config");
- mutex_init(&icap_sem);

devt = MKDEV(XHWICAP_MAJOR, XHWICAP_MINOR);
retval = register_chrdev_region(devt,


2021-04-10 08:58:55

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH -next] char: xilinx_hwicap: use DEFINE_MUTEX() for mutex lock

On Fri, Apr 09, 2021 at 05:51:36PM +0800, Ye Bin wrote:
> mutex lock can be initialized automatically with DEFINE_MUTEX()
> rather than explicitly calling mutex_init().
>
> Reported-by: Hulk Robot <[email protected]>
> Signed-off-by: Ye Bin <[email protected]>
> ---
> drivers/char/xilinx_hwicap/xilinx_hwicap.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
> index 067396bedf22..4d586233dfa4 100644
> --- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
> +++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
> @@ -111,7 +111,7 @@
> /* An array, which is set to true when the device is registered. */
> static DEFINE_MUTEX(hwicap_mutex);
> static bool probed_devices[HWICAP_DEVICES];
> -static struct mutex icap_sem;
> +static DEFINE_MUTEX(icap_sem);
>
> static struct class *icap_class;
>
> @@ -857,7 +857,6 @@ static int __init hwicap_module_init(void)
> int retval;
>
> icap_class = class_create(THIS_MODULE, "xilinx_config");
> - mutex_init(&icap_sem);
>
> devt = MKDEV(XHWICAP_MAJOR, XHWICAP_MINOR);
> retval = register_chrdev_region(devt,
>

What actually does this help out with? Why is it wrong to explicitly
call mutex_init() instead of a magic macro?

What good are these changes causing?

thanks,

greg k-h