* [PATCH] usb: core: Remove redundant NULL checks before kfree
@ 2022-06-06 1:43 cgel.zte
2022-06-10 9:06 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: cgel.zte @ 2022-06-06 1:43 UTC (permalink / raw)
To: gregkh
Cc: oneukum, olebowle, linux-usb, linux-kernel, Minghao Chi, Zeal Robot
From: Minghao Chi <chi.minghao@zte.com.cn>
Checking a pointer for NULL before calling kfree() on it is redundant,
kfree() deals with NULL pointers just fine.
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
---
drivers/usb/core/quirks.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index f99a65a64588..7e918e4a95f2 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -56,10 +56,8 @@ static int quirks_param_set(const char *value, const struct kernel_param *kp)
if (val[i] == ',')
quirk_count++;
- if (quirk_list) {
- kfree(quirk_list);
- quirk_list = NULL;
- }
+ kfree(quirk_list);
+ quirk_list = NULL;
quirk_list = kcalloc(quirk_count, sizeof(struct quirk_entry),
GFP_KERNEL);
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: core: Remove redundant NULL checks before kfree
2022-06-06 1:43 [PATCH] usb: core: Remove redundant NULL checks before kfree cgel.zte
@ 2022-06-10 9:06 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2022-06-10 9:06 UTC (permalink / raw)
To: cgel.zte
Cc: oneukum, olebowle, linux-usb, linux-kernel, Minghao Chi, Zeal Robot
On Mon, Jun 06, 2022 at 01:43:52AM +0000, cgel.zte@gmail.com wrote:
> From: Minghao Chi <chi.minghao@zte.com.cn>
>
> Checking a pointer for NULL before calling kfree() on it is redundant,
> kfree() deals with NULL pointers just fine.
>
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
> ---
> drivers/usb/core/quirks.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
> index f99a65a64588..7e918e4a95f2 100644
> --- a/drivers/usb/core/quirks.c
> +++ b/drivers/usb/core/quirks.c
> @@ -56,10 +56,8 @@ static int quirks_param_set(const char *value, const struct kernel_param *kp)
> if (val[i] == ',')
> quirk_count++;
>
> - if (quirk_list) {
> - kfree(quirk_list);
> - quirk_list = NULL;
> - }
> + kfree(quirk_list);
> + quirk_list = NULL;
Why are you setting this to NULL right before you assign it again:
> quirk_list = kcalloc(quirk_count, sizeof(struct quirk_entry),
> GFP_KERNEL);
Please just free and move on.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-06-10 9:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-06 1:43 [PATCH] usb: core: Remove redundant NULL checks before kfree cgel.zte
2022-06-10 9:06 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®