2018-08-02 08:46:08

by Ocean He

[permalink] [raw]
Subject: [PATCH v2] ACPI: nfit: remove redundant assignment if nfit_mem found

From: Ocean He <[email protected]>

When nfit_mem is found via list_for_each_entry, it has already been
assigned valid value. There is no need to assign it again in the following
codes.

Signed-off-by: Ocean He <[email protected]>
---
v1: https://patchwork.kernel.org/patch/10553277/
v2: Sorry for noise. I got an email problem, so I have to resend to loop
[email protected].

drivers/acpi/nfit/core.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index 7c47900..85dde54 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -1048,9 +1048,7 @@ static int __nfit_mem_init(struct acpi_nfit_desc *acpi_desc,
break;
}

- if (found)
- nfit_mem = found;
- else {
+ if (!found) {
nfit_mem = devm_kzalloc(acpi_desc->dev,
sizeof(*nfit_mem), GFP_KERNEL);
if (!nfit_mem)
--
1.8.3.1



2018-08-10 23:46:46

by Verma, Vishal L

[permalink] [raw]
Subject: Re: [PATCH v2] ACPI: nfit: remove redundant assignment if nfit_mem found


On Thu, 2018-08-02 at 04:44 -0400, [email protected] wrote:
> From: Ocean He <[email protected]>
>
> When nfit_mem is found via list_for_each_entry, it has already been
> assigned valid value. There is no need to assign it again in the
> following
> codes.
>
> Signed-off-by: Ocean He <[email protected]>
> ---
> v1: https://patchwork.kernel.org/patch/10553277/
> v2: Sorry for noise. I got an email problem, so I have to resend to
> loop
> [email protected].
>
> drivers/acpi/nfit/core.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
> index 7c47900..85dde54 100644
> --- a/drivers/acpi/nfit/core.c
> +++ b/drivers/acpi/nfit/core.c
> @@ -1048,9 +1048,7 @@ static int __nfit_mem_init(struct
> acpi_nfit_desc *acpi_desc,
> break;
> }
>
> - if (found)
> - nfit_mem = found;
> - else {
> + if (!found) {

Hi Ocean,

While this is technically correct, the old way was easier to read. We
loop through and find the matching handle. If we found one, then
nfit_mem was whatever was found. If not, we allocate it.

With this change, one has to go grok the list_for_.. loop to figure out
where nfit_mem is coming from. I'd personally prefer to keep the
existing way..

> nfit_mem = devm_kzalloc(acpi_desc->dev,
> sizeof(*nfit_mem),
> GFP_KERNEL);
> if (!nfit_mem)

2018-08-13 02:55:20

by Ocean HY1 He

[permalink] [raw]
Subject: RE: [External] Re: [PATCH v2] ACPI: nfit: remove redundant assignment if nfit_mem found



> -----Original Message-----
> From: Verma, Vishal L <[email protected]>
> Sent: Saturday, August 11, 2018 7:46 AM
> To: Williams, Dan J <[email protected]>; [email protected];
> [email protected]; Jiang, Dave <[email protected]>; [email protected];
> [email protected]
> Cc: [email protected]; [email protected]; linux-
> [email protected]; Ocean HY1 He <[email protected]>
> Subject: [External] Re: [PATCH v2] ACPI: nfit: remove redundant assignment if
> nfit_mem found
>
>
> On Thu, 2018-08-02 at 04:44 -0400, [email protected] wrote:
> > From: Ocean He <[email protected]>
> >
> > When nfit_mem is found via list_for_each_entry, it has already been
> > assigned valid value. There is no need to assign it again in the
> > following
> > codes.
> >
> > Signed-off-by: Ocean He <[email protected]>
> > ---
> > v1: https://patchwork.kernel.org/patch/10553277/
> > v2: Sorry for noise. I got an email problem, so I have to resend to
> > loop
> > [email protected].
> >
> > drivers/acpi/nfit/core.c | 4 +---
> > 1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
> > index 7c47900..85dde54 100644
> > --- a/drivers/acpi/nfit/core.c
> > +++ b/drivers/acpi/nfit/core.c
> > @@ -1048,9 +1048,7 @@ static int __nfit_mem_init(struct
> > acpi_nfit_desc *acpi_desc,
> > break;
> > }
> >
> > - if (found)
> > - nfit_mem = found;
> > - else {
> > + if (!found) {
>
> Hi Ocean,
>
> While this is technically correct, the old way was easier to read. We
> loop through and find the matching handle. If we found one, then
> nfit_mem was whatever was found. If not, we allocate it.
>
> With this change, one has to go grok the list_for_.. loop to figure out
> where nfit_mem is coming from. I'd personally prefer to keep the
> existing way..
>
Hi Verma,

You're right that it took me some time to find out where nfit_mem
was found, when I look these codes at first.

It's reasonable to keep the existing way for well readability.

Thanks,
Ocean.
> > nfit_mem = devm_kzalloc(acpi_desc->dev,
> > sizeof(*nfit_mem),
> > GFP_KERNEL);
> > if (!nfit_mem)