All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Jeremy Sowden <jeremy@azazel.net>
Cc: Linux Driver Project Developer List
	<driverdev-devel@linuxdriverproject.org>
Subject: Re: [PATCH] staging: kpc2000: simplify nested conditionals that just return a boolean.
Date: Fri, 24 May 2019 16:16:07 +0200	[thread overview]
Message-ID: <20190524141607.GA3766@kroah.com> (raw)
In-Reply-To: <20190524121926.32487-1-jeremy@azazel.net>

On Fri, May 24, 2019 at 01:19:26PM +0100, Jeremy Sowden wrote:
> kp2000_check_uio_irq contained a pair of nested ifs which each evaluated
> a bitwise operation.  If both operations yielded true, the function
> returned 1; otherwise it returned 0.
> 
> Replaced the whole thing with one return statement that evaluates the
> combination of both bitwise operations.

Does this really do the same thing?

> 
> Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
> ---
> This applies to staging-testing.
> 
> I was in two minds whether to send this patch or something less terse:
> 
> +	return (interrupt_active & irq_check_mask) &&
> +	       (interrupt_mask_inv & irq_check_mask);
> 
>  drivers/staging/kpc2000/kpc2000/cell_probe.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
> index f731a97c6cac..d10f695b6673 100644
> --- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
> +++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
> @@ -240,12 +240,10 @@ int  kp2000_check_uio_irq(struct kp2000_device *pcard, u32 irq_num)
>  	u64 interrupt_mask_inv = ~readq(pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
>  	u64 irq_check_mask = (1 << irq_num);
>  
> -	if (interrupt_active & irq_check_mask) { // if it's active (interrupt pending)
> -		if (interrupt_mask_inv & irq_check_mask) {    // and if it's not masked off
> -			return 1;
> -		}
> -	}
> -	return 0;
> +	/*
> +	 * Is the IRQ active (interrupt pending) and not masked off?
> +	 */
> +	return (interrupt_active & interrupt_mask_inv & irq_check_mask) != 0;

I have no idea what these bits really are, but try the above with the
following values:
	interrupt_active = BIT(0);
	interrupt_mask_inv = BIT(1);
	irq_check_mask = (BIT(1) | BIT(0));

So in your new code you have:
	BIT(0) & BIT(1) & (BIT(1) | BIT(0))
which reduces to:
	0 & (BIT(1) | BIT(0))
which then reduces to:
	0

The original if statements will return 1.
Your new one will return 0.

You can't AND interrupt_active with interrupt_mask_inv like you did
here, right?

Or am I reading this all wrong?

And what's wrong with the original code here?  What is complaining about
it (other than the crazy comment style...)?

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  reply	other threads:[~2019-05-24 14:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-24 12:19 [PATCH] staging: kpc2000: simplify nested conditionals that just return a boolean Jeremy Sowden
2019-05-24 14:16 ` Greg KH [this message]
2019-05-24 16:59   ` Matt Sickler
2019-05-26  9:13     ` Jeremy Sowden
2019-05-25 14:23 ` Dan Carpenter

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=20190524141607.GA3766@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=jeremy@azazel.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.