public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <bjorn.helgaas@hp.com>
To: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
Cc: Len Brown <lenb@kernel.org>, linux acpi <linux-acpi@vger.kernel.org>
Subject: Re: [RFC] acpi: remove redundant NULL checks in acpi drivers
Date: Thu, 10 Sep 2009 16:36:55 -0600	[thread overview]
Message-ID: <200909101636.56398.bjorn.helgaas@hp.com> (raw)
In-Reply-To: <4AA92CAD.8020208@tuffmail.co.uk>

On Thursday 10 September 2009 10:43:25 am Alan Jenkins wrote:
> I noticed a pattern of unnecessary checks, and wrote some semantic
> patches to remove them (using the spatch tool).  Here are the
> results, modulo some manual adjustment of blank lines to try and
> preserve the coding style in different files.
> 
> Would you be interested in accepting this?  Can I submit it like
> this, or should I break it up somehow?

I'm generally in favor of removing these checks.  In most cases,
you can go even farther, for example:

> diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
> index 98b9690..57fbf70 100644
> --- a/drivers/acpi/ac.c
> +++ b/drivers/acpi/ac.c
> @@ -259,9 +259,6 @@ static int acpi_ac_add(struct acpi_device *device)
>  	struct acpi_ac *ac = NULL;

The initialization of "ac" is useless since the first thing we
do below is assign to it.

> -	if (!device)
> -		return -EINVAL;
> -
>  	ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL);
>  	if (!ac)
>  		return -ENOMEM;
> @@ -306,11 +303,10 @@ static int acpi_ac_add(struct acpi_device *device)
>  
>  static int acpi_ac_resume(struct acpi_device *device)
>  {
> -	struct acpi_ac *ac;
> +	struct acpi_ac *ac = acpi_driver_data(device);
>  	unsigned old_state;
> -	if (!device || !acpi_driver_data(device))
> +	if (!ac)
>  		return -EINVAL;

I would also remove the test of "!ac".  acpi_ac_resume() can only
be called after acpi_ac_add() completes successfully, and acpi_ac_add()
always sets "device->driver_data = ac".

So testing "!ac" here will only find memory corruption or a bug in
the Linux/ACPI core.  In either case, I think it's better to oops
than to return -EINVAL, which will probably get ignored.

Bjorn


      reply	other threads:[~2009-09-10 22:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-10 16:43 [RFC] acpi: remove redundant NULL checks in acpi drivers Alan Jenkins
2009-09-10 22:36 ` Bjorn Helgaas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200909101636.56398.bjorn.helgaas@hp.com \
    --to=bjorn.helgaas@hp.com \
    --cc=alan-jenkins@tuffmail.co.uk \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox