diff mbox

[2/2] add irq validity check in tpm_i2c_nuvoton driver

Message ID 20160712173326.GA9286@obsidianresearch.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jason Gunthorpe July 12, 2016, 5:33 p.m. UTC
On Wed, Jun 29, 2016 at 05:03:39PM +0300, Jarkko Sakkinen wrote:
> On Wed, Jun 29, 2016 at 12:58:49PM +0300, andrew zamansky wrote:
> > if irq==0 (actualy invalid value) then error is printed to dmesg after
> > trying to register to 0 interrupt 
> > 
> >  drivers/char/tpm/tpm_i2c_nuvoton.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_nuvoton.c
> > index 75a80e466..3081529 100644
> > +++ b/drivers/char/tpm/tpm_i2c_nuvoton.c
> > @@ -554,7 +554,9 @@ static int i2c_nuvoton_probe(struct i2c_client *client,
> >  	 *   TPM_INTF_INT_LEVEL_LOW | TPM_INTF_DATA_AVAIL_INT
> >  	 * The IRQ should be set in the i2c_board_info (which is done
> >  	 * automatically in of_i2c_register_devices, for device tree users */
> > -	chip->flags |= TPM_CHIP_FLAG_IRQ;
> > +	if(chip->flags)
> > +		chip->flags |= TPM_CHIP_FLAG_IRQ;
> > +
> >  	priv->irq = client->irq;
> >  
> >  	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> 
> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> 
> PS. There's a style error. "if()" should be "if ()". I don't mind fixing
> that. Just remember that next time.

Andrew/Jarkko:

Uhm, this looks wrong to me.. The original code was like this:

-       chip->vendor.irq = client->irq;
-       if (chip->vendor.irq) {

And was wrongly changed to this:

+       chip->flags |= TPM_CHIP_FLAG_IRQ;
+       priv->irq = client->irq;
+       if (chip->flags & TPM_CHIP_FLAG_IRQ) {

Jarkko, can you fold this into the patch to fix it please:


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev

Comments

Jarkko Sakkinen July 13, 2016, 12:04 p.m. UTC | #1
On Tue, Jul 12, 2016 at 11:33:26AM -0600, Jason Gunthorpe wrote:
> On Wed, Jun 29, 2016 at 05:03:39PM +0300, Jarkko Sakkinen wrote:
> > On Wed, Jun 29, 2016 at 12:58:49PM +0300, andrew zamansky wrote:
> > > if irq==0 (actualy invalid value) then error is printed to dmesg after
> > > trying to register to 0 interrupt 
> > > 
> > >  drivers/char/tpm/tpm_i2c_nuvoton.c | 4 +++-
> > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_nuvoton.c
> > > index 75a80e466..3081529 100644
> > > +++ b/drivers/char/tpm/tpm_i2c_nuvoton.c
> > > @@ -554,7 +554,9 @@ static int i2c_nuvoton_probe(struct i2c_client *client,
> > >  	 *   TPM_INTF_INT_LEVEL_LOW | TPM_INTF_DATA_AVAIL_INT
> > >  	 * The IRQ should be set in the i2c_board_info (which is done
> > >  	 * automatically in of_i2c_register_devices, for device tree users */
> > > -	chip->flags |= TPM_CHIP_FLAG_IRQ;
> > > +	if(chip->flags)
> > > +		chip->flags |= TPM_CHIP_FLAG_IRQ;
> > > +
> > >  	priv->irq = client->irq;
> > >  
> > >  	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > 
> > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > 
> > PS. There's a style error. "if()" should be "if ()". I don't mind fixing
> > that. Just remember that next time.
> 
> Andrew/Jarkko:
> 
> Uhm, this looks wrong to me.. The original code was like this:
> 
> -       chip->vendor.irq = client->irq;
> -       if (chip->vendor.irq) {
> 
> And was wrongly changed to this:
> 
> +       chip->flags |= TPM_CHIP_FLAG_IRQ;
> +       priv->irq = client->irq;
> +       if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> 
> Jarkko, can you fold this into the patch to fix it please:

Right. Sure. It's not merged to my next nor it has been part of any pull
request so this is still doable.

/Jarkko

> diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_nuvoton.c
> index e63ea1652d8d..826698234336 100644
> --- a/drivers/char/tpm/tpm_i2c_nuvoton.c
> +++ b/drivers/char/tpm/tpm_i2c_nuvoton.c
> @@ -559,12 +559,8 @@ static int i2c_nuvoton_probe(struct i2c_client *client,
>  	 *   TPM_INTF_INT_LEVEL_LOW | TPM_INTF_DATA_AVAIL_INT
>  	 * The IRQ should be set in the i2c_board_info (which is done
>  	 * automatically in of_i2c_register_devices, for device tree users */
> -	if(chip->flags)
> -		chip->flags |= TPM_CHIP_FLAG_IRQ;
> -
>  	priv->irq = client->irq;
> -
> -	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> +	if (client->irq) {
>  		dev_dbg(dev, "%s() priv->irq\n", __func__);
>  		rc = devm_request_irq(dev, client->irq,
>  				      i2c_nuvoton_int_handler,
> @@ -574,9 +570,9 @@ static int i2c_nuvoton_probe(struct i2c_client *client,
>  		if (rc) {
>  			dev_err(dev, "%s() Unable to request irq: %d for use\n",
>  				__func__, priv->irq);
> -			chip->flags &= ~TPM_CHIP_FLAG_IRQ;
>  			priv->irq = 0;
>  		} else {
> +			chip->flags |= TPM_CHIP_FLAG_IRQ;
>  			/* Clear any pending interrupt */
>  			i2c_nuvoton_ready(chip);
>  			/* - wait for TPM_STS==0xA0 (stsValid, commandReady) */

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
Jarkko Sakkinen July 18, 2016, 5:50 p.m. UTC | #2
On Wed, Jul 13, 2016 at 03:04:01PM +0300, Jarkko Sakkinen wrote:
> On Tue, Jul 12, 2016 at 11:33:26AM -0600, Jason Gunthorpe wrote:
> > On Wed, Jun 29, 2016 at 05:03:39PM +0300, Jarkko Sakkinen wrote:
> > > On Wed, Jun 29, 2016 at 12:58:49PM +0300, andrew zamansky wrote:
> > > > if irq==0 (actualy invalid value) then error is printed to dmesg after
> > > > trying to register to 0 interrupt 
> > > > 
> > > >  drivers/char/tpm/tpm_i2c_nuvoton.c | 4 +++-
> > > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_nuvoton.c
> > > > index 75a80e466..3081529 100644
> > > > +++ b/drivers/char/tpm/tpm_i2c_nuvoton.c
> > > > @@ -554,7 +554,9 @@ static int i2c_nuvoton_probe(struct i2c_client *client,
> > > >  	 *   TPM_INTF_INT_LEVEL_LOW | TPM_INTF_DATA_AVAIL_INT
> > > >  	 * The IRQ should be set in the i2c_board_info (which is done
> > > >  	 * automatically in of_i2c_register_devices, for device tree users */
> > > > -	chip->flags |= TPM_CHIP_FLAG_IRQ;
> > > > +	if(chip->flags)
> > > > +		chip->flags |= TPM_CHIP_FLAG_IRQ;
> > > > +
> > > >  	priv->irq = client->irq;
> > > >  
> > > >  	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > 
> > > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > 
> > > PS. There's a style error. "if()" should be "if ()". I don't mind fixing
> > > that. Just remember that next time.
> > 
> > Andrew/Jarkko:
> > 
> > Uhm, this looks wrong to me.. The original code was like this:
> > 
> > -       chip->vendor.irq = client->irq;
> > -       if (chip->vendor.irq) {
> > 
> > And was wrongly changed to this:
> > 
> > +       chip->flags |= TPM_CHIP_FLAG_IRQ;
> > +       priv->irq = client->irq;
> > +       if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > 
> > Jarkko, can you fold this into the patch to fix it please:
> 
> Right. Sure. It's not merged to my next nor it has been part of any pull
> request so this is still doable.

Done.

/Jarkko

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
Jarkko Sakkinen July 19, 2016, 2:35 p.m. UTC | #3
On Mon, Jul 18, 2016 at 08:50:53PM +0300, Jarkko Sakkinen wrote:
> On Wed, Jul 13, 2016 at 03:04:01PM +0300, Jarkko Sakkinen wrote:
> > On Tue, Jul 12, 2016 at 11:33:26AM -0600, Jason Gunthorpe wrote:
> > > On Wed, Jun 29, 2016 at 05:03:39PM +0300, Jarkko Sakkinen wrote:
> > > > On Wed, Jun 29, 2016 at 12:58:49PM +0300, andrew zamansky wrote:
> > > > > if irq==0 (actualy invalid value) then error is printed to dmesg after
> > > > > trying to register to 0 interrupt 
> > > > > 
> > > > >  drivers/char/tpm/tpm_i2c_nuvoton.c | 4 +++-
> > > > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > > > 
> > > > > diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_nuvoton.c
> > > > > index 75a80e466..3081529 100644
> > > > > +++ b/drivers/char/tpm/tpm_i2c_nuvoton.c
> > > > > @@ -554,7 +554,9 @@ static int i2c_nuvoton_probe(struct i2c_client *client,
> > > > >  	 *   TPM_INTF_INT_LEVEL_LOW | TPM_INTF_DATA_AVAIL_INT
> > > > >  	 * The IRQ should be set in the i2c_board_info (which is done
> > > > >  	 * automatically in of_i2c_register_devices, for device tree users */
> > > > > -	chip->flags |= TPM_CHIP_FLAG_IRQ;
> > > > > +	if(chip->flags)
> > > > > +		chip->flags |= TPM_CHIP_FLAG_IRQ;
> > > > > +
> > > > >  	priv->irq = client->irq;
> > > > >  
> > > > >  	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > > 
> > > > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > > 
> > > > PS. There's a style error. "if()" should be "if ()". I don't mind fixing
> > > > that. Just remember that next time.
> > > 
> > > Andrew/Jarkko:
> > > 
> > > Uhm, this looks wrong to me.. The original code was like this:
> > > 
> > > -       chip->vendor.irq = client->irq;
> > > -       if (chip->vendor.irq) {
> > > 
> > > And was wrongly changed to this:
> > > 
> > > +       chip->flags |= TPM_CHIP_FLAG_IRQ;
> > > +       priv->irq = client->irq;
> > > +       if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > 
> > > Jarkko, can you fold this into the patch to fix it please:
> > 
> > Right. Sure. It's not merged to my next nor it has been part of any pull
> > request so this is still doable.
> 
> Done.

I rewrote the whole description as this is actually a bug fix for a
regression. I also added a fixes line.

/Jarkko

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
diff mbox

Patch

diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_nuvoton.c
index e63ea1652d8d..826698234336 100644
--- a/drivers/char/tpm/tpm_i2c_nuvoton.c
+++ b/drivers/char/tpm/tpm_i2c_nuvoton.c
@@ -559,12 +559,8 @@  static int i2c_nuvoton_probe(struct i2c_client *client,
 	 *   TPM_INTF_INT_LEVEL_LOW | TPM_INTF_DATA_AVAIL_INT
 	 * The IRQ should be set in the i2c_board_info (which is done
 	 * automatically in of_i2c_register_devices, for device tree users */
-	if(chip->flags)
-		chip->flags |= TPM_CHIP_FLAG_IRQ;
-
 	priv->irq = client->irq;
-
-	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
+	if (client->irq) {
 		dev_dbg(dev, "%s() priv->irq\n", __func__);
 		rc = devm_request_irq(dev, client->irq,
 				      i2c_nuvoton_int_handler,
@@ -574,9 +570,9 @@  static int i2c_nuvoton_probe(struct i2c_client *client,
 		if (rc) {
 			dev_err(dev, "%s() Unable to request irq: %d for use\n",
 				__func__, priv->irq);
-			chip->flags &= ~TPM_CHIP_FLAG_IRQ;
 			priv->irq = 0;
 		} else {
+			chip->flags |= TPM_CHIP_FLAG_IRQ;
 			/* Clear any pending interrupt */
 			i2c_nuvoton_ready(chip);
 			/* - wait for TPM_STS==0xA0 (stsValid, commandReady) */