[PATCH 1/2] staging: media: Remove NULL test on an already tested value

Abraham Samuel Adekunle posted 2 patches 8 months, 2 weeks ago
There is a newer version of this series
[PATCH 1/2] staging: media: Remove NULL test on an already tested value
Posted by Abraham Samuel Adekunle 8 months, 2 weeks ago
When a value has been tested for NULL in an expression, a
second NULL test on the same value in another expression
is unnecessary when the value has not been assigned NULL.

Remove unnecessary duplicate NULL tests on the same value that
has previously been NULL tested.

Found by Coccinelle

Signed-off-by: Abraham Samuel Adekunle <abrahamadekunle50@gmail.com>
---
 drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c | 2 +-
 drivers/staging/media/av7110/sp8870.c                     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
index e176483df301..0abac820299a 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
@@ -1292,7 +1292,7 @@ static int gmin_get_config_dsm_var(struct device *dev,
 	 * if it founds something different than string, letting it
 	 * to fall back to the old code.
 	 */
-	if (cur && cur->type != ACPI_TYPE_STRING) {
+	if (cur->type != ACPI_TYPE_STRING) {
 		dev_info(dev, "found non-string _DSM entry for '%s'\n", var);
 		ACPI_FREE(obj);
 		return -EINVAL;
diff --git a/drivers/staging/media/av7110/sp8870.c b/drivers/staging/media/av7110/sp8870.c
index 0c813860f5b2..8c5fa5ed5340 100644
--- a/drivers/staging/media/av7110/sp8870.c
+++ b/drivers/staging/media/av7110/sp8870.c
@@ -508,7 +508,7 @@ static int sp8870_set_frontend(struct dvb_frontend *fe)
 	}
 
 	if (debug) {
-		if (valid) {
+		{
 			if (trials > 1) {
 				pr_info("%s(): firmware lockup!!!\n", __func__);
 				pr_info("%s(): recovered after %i trial(s))\n",  __func__, trials - 1);
-- 
2.34.1
Re: [PATCH 1/2] staging: media: Remove NULL test on an already tested value
Posted by Andy Shevchenko 8 months, 2 weeks ago
On Thu, Apr 3, 2025 at 2:30 AM Abraham Samuel Adekunle
<abrahamadekunle50@gmail.com> wrote:
>
> When a value has been tested for NULL in an expression, a
> second NULL test on the same value in another expression
> is unnecessary when the value has not been assigned NULL.
>
> Remove unnecessary duplicate NULL tests on the same value that
> has previously been NULL tested.

>  drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c | 2 +-
>  drivers/staging/media/av7110/sp8870.c                     | 2 +-

Please, split this on per driver basis, as they have different
maintainers and trees to go through.

...

> --- a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
> +++ b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
> @@ -1292,7 +1292,7 @@ static int gmin_get_config_dsm_var(struct device *dev,
>          * if it founds something different than string, letting it
>          * to fall back to the old code.
>          */
> -       if (cur && cur->type != ACPI_TYPE_STRING) {
> +       if (cur->type != ACPI_TYPE_STRING) {
>                 dev_info(dev, "found non-string _DSM entry for '%s'\n", var);
>                 ACPI_FREE(obj);
>                 return -EINVAL;

This change is good.

...

> diff --git a/drivers/staging/media/av7110/sp8870.c b/drivers/staging/media/av7110/sp8870.c
> index 0c813860f5b2..8c5fa5ed5340 100644
> --- a/drivers/staging/media/av7110/sp8870.c
> +++ b/drivers/staging/media/av7110/sp8870.c
> @@ -508,7 +508,7 @@ static int sp8870_set_frontend(struct dvb_frontend *fe)
>         }
>
>         if (debug) {
> -               if (valid) {
> +               {
>                         if (trials > 1) {
>                                 pr_info("%s(): firmware lockup!!!\n", __func__);
>                                 pr_info("%s(): recovered after %i trial(s))\n",  __func__, trials - 1);

But this is not fully done. Why do we need to keep {}? Just shift left
the code and remove those {} altogether.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH 1/2] staging: media: Remove NULL test on an already tested value
Posted by Samuel Abraham 8 months, 2 weeks ago
On Thu, Apr 3, 2025 at 6:19 AM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Thu, Apr 3, 2025 at 2:30 AM Abraham Samuel Adekunle
> <abrahamadekunle50@gmail.com> wrote:
> >
> > When a value has been tested for NULL in an expression, a
> > second NULL test on the same value in another expression
> > is unnecessary when the value has not been assigned NULL.
> >
> > Remove unnecessary duplicate NULL tests on the same value that
> > has previously been NULL tested.
>
> >  drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c | 2 +-
> >  drivers/staging/media/av7110/sp8870.c                     | 2 +-
>
> Please, split this on per driver basis, as they have different
> maintainers and trees to go through.

Thank you for your review.
I will do that.
>
> ...
>
> > --- a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
> > +++ b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
> > @@ -1292,7 +1292,7 @@ static int gmin_get_config_dsm_var(struct device *dev,
> >          * if it founds something different than string, letting it
> >          * to fall back to the old code.
> >          */
> > -       if (cur && cur->type != ACPI_TYPE_STRING) {
> > +       if (cur->type != ACPI_TYPE_STRING) {
> >                 dev_info(dev, "found non-string _DSM entry for '%s'\n", var);
> >                 ACPI_FREE(obj);
> >                 return -EINVAL;
>
> This change is good.
>
> ...
>
> > diff --git a/drivers/staging/media/av7110/sp8870.c b/drivers/staging/media/av7110/sp8870.c
> > index 0c813860f5b2..8c5fa5ed5340 100644
> > --- a/drivers/staging/media/av7110/sp8870.c
> > +++ b/drivers/staging/media/av7110/sp8870.c
> > @@ -508,7 +508,7 @@ static int sp8870_set_frontend(struct dvb_frontend *fe)
> >         }
> >
> >         if (debug) {
> > -               if (valid) {
> > +               {
> >                         if (trials > 1) {
> >                                 pr_info("%s(): firmware lockup!!!\n", __func__);
> >                                 pr_info("%s(): recovered after %i trial(s))\n",  __func__, trials - 1);
>
> But this is not fully done. Why do we need to keep {}? Just shift left
> the code and remove those {} altogether.

Okay I will effect the change.
Thanks

Adekunle