2014-06-20 20:38:07

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH 1/1] net/dsa/dsa.c: remove null test before kfree

Fix checkpatch warning:
WARNING: kfree(NULL) is safe this check is probably not required

Cc: "David S. Miller" <[email protected]>
Cc: Grant Likely <[email protected]>
Cc: [email protected]
Signed-off-by: Fabian Frederick <[email protected]>
---
net/dsa/dsa.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 5db37ce..0a49632 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -351,8 +351,7 @@ static void dsa_of_free_platform_data(struct dsa_platform_data *pd)
for (i = 0; i < pd->nr_chips; i++) {
port_index = 0;
while (port_index < DSA_MAX_PORTS) {
- if (pd->chip[i].port_names[port_index])
- kfree(pd->chip[i].port_names[port_index]);
+ kfree(pd->chip[i].port_names[port_index]);
port_index++;
}
kfree(pd->chip[i].rtable);
--
1.8.4.5


2014-06-21 08:37:40

by Bjørn Mork

[permalink] [raw]
Subject: Re: [PATCH 1/1] net/dsa/dsa.c: remove null test before kfree



On 20 June 2014 22:36:47 CEST, Fabian Frederick <[email protected]> wrote:
>Fix checkpatch warning:
>WARNING: kfree(NULL) is safe this check is probably not required

"probably not" implies that there are cases where the check *is* required. That means that your commit message should explain why this particular check is redundant.

I haven't analyzed your changes here, so they could be fine for all I know. My point is that such analysis is your job when submitting cleanups like this one.



Bjørn

2014-06-21 09:36:44

by Fabian Frédérick

[permalink] [raw]
Subject: Re: [PATCH 1/1] net/dsa/dsa.c: remove null test before kfree

On Sat, 21 Jun 2014 10:37:24 +0200
Bj?rn Mork <[email protected]> wrote:

>
>
> On 20 June 2014 22:36:47 CEST, Fabian Frederick <[email protected]> wrote:
> >Fix checkpatch warning:
> >WARNING: kfree(NULL) is safe this check is probably not required
>
> "probably not" implies that there are cases where the check *is* required. That means that your commit message should explain why this particular check is redundant.
>
> I haven't analyzed your changes here, so they could be fine for all I know. My point is that such analysis is your job when submitting cleanups like this one.
>
>
>
AFAIK, any

if(foo)
kfree(foo)

can be updated to kfree(foo) but

if (foo){
kfree(foo)
do something else
}

has to be evaluated ; reason for the "probably" in warning message.
If I'm wrong maybe we could be more verbose in checkpatch :)
(I added Joe Perches in Cc list ; maybe he can help here)

Fabian

> Bj?rn

2014-06-21 14:10:12

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 1/1] net/dsa/dsa.c: remove null test before kfree

On Sat, 2014-06-21 at 11:36 +0200, Fabian Frederick wrote:
> On Sat, 21 Jun 2014 10:37:24 +0200 Bj?rn Mork <[email protected]> wrote:
> > On 20 June 2014 22:36:47 CEST, Fabian Frederick <[email protected]> wrote:
> > > Fix checkpatch warning:
> > > WARNING: kfree(NULL) is safe this check is probably not required
> >
> > "probably not" implies that there are cases where the check *is*
> > required. That means that your commit message should explain why
> > this particular check is redundant.
> >
> > I haven't analyzed your changes here, so they could be fine for all
> > I know. My point is that such analysis is your job when submitting
> > cleanups like this one.
> AFAIK, any
>
> if(foo)
> kfree(foo)
>
> can be updated to kfree(foo) but
>
> if (foo){
> kfree(foo)
> do something else
> }
>
> has to be evaluated ; reason for the "probably" in warning message.
> If I'm wrong maybe we could be more verbose in checkpatch :)

I think Bj?rn is correct here.

Just because checkpatch bleats some message or another,
it's still the submitter's job to validate the code.

In this case, it seems the simple substitution of
"unnecessary null" to the subject would have been
enough validation.

I don't think checkpatch needs updating for this, but
maybe you could propose better language.

2014-06-22 02:22:46

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 1/1] net/dsa/dsa.c: remove null test before kfree

From: Joe Perches <[email protected]>
Date: Sat, 21 Jun 2014 07:10:06 -0700

> In this case, it seems the simple substitution of
> "unnecessary null" to the subject would have been
> enough validation.

Agreed.