diff mbox series

[v4,1/5] i2c: nvidia-gpu: refactor master_xfer

Message ID 20190603170545.24004-2-ajayg@nvidia.com (mailing list archive)
State Superseded
Headers show
Series usb: typec: ucsi: ccg: add runtime pm support | expand

Commit Message

Ajay Gupta June 3, 2019, 5:05 p.m. UTC
From: Ajay Gupta <ajayg@nvidia.com>

Added a local variable "send_stop" to simplify "goto" statements.

The "send_stop" handles below two case
1) When first i2c start fails and so i2c stop is not sent before
exiting

2) When i2c stop failed after all transfers and we do not need to
send another stop before exiting.

Signed-off-by: Ajay Gupta <ajayg@nvidia.com>
---
Changes from v3->v4:
	- Further refactor master_xfer based on Wolfram's comment.

 drivers/i2c/busses/i2c-nvidia-gpu.c | 30 +++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

Comments

Wolfram Sang June 7, 2019, 8:33 a.m. UTC | #1
> Changes from v3->v4:
> 	- Further refactor master_xfer based on Wolfram's comment.

Yay, looks even better. One thing to improve, though.

>  	status = gpu_i2c_stop(i2cd);

send_stop = false;

> -	if (status < 0)
> -		return status;
> +	if (status < 0) {
> +		send_stop = false;

and skip it here...

> +		goto exit;
> +	}
>  
> -	return i;
> -stop:
> -	status2 = gpu_i2c_stop(i2cd);
> -	if (status2 < 0)
> -		dev_err(i2cd->dev, "i2c stop failed %d\n", status2);
> +	send_stop = false;

... and here.
Ajay Gupta June 7, 2019, 3:47 p.m. UTC | #2
Hi Wolfram,

> -----Original Message-----
> From: Wolfram Sang <wsa@the-dreams.de>
> Sent: Friday, June 7, 2019 1:33 AM
> To: Ajay Gupta <ajaykuee@gmail.com>
> Cc: heikki.krogerus@linux.intel.com; linux-usb@vger.kernel.org; linux-
> i2c@vger.kernel.org; Ajay Gupta <ajayg@nvidia.com>
> Subject: Re: [PATCH v4 1/5] i2c: nvidia-gpu: refactor master_xfer
> 
> > Changes from v3->v4:
> > 	- Further refactor master_xfer based on Wolfram's comment.
> 
> Yay, looks even better. One thing to improve, though.
> 
> >  	status = gpu_i2c_stop(i2cd);
> 
> send_stop = false;

> 
> > -	if (status < 0)
> > -		return status;
> > +	if (status < 0) {
> > +		send_stop = false;
> 
> and skip it here...
> 
> > +		goto exit;
> > +	}
> >
> > -	return i;
> > -stop:
> > -	status2 = gpu_i2c_stop(i2cd);
> > -	if (status2 < 0)
> > -		dev_err(i2cd->dev, "i2c stop failed %d\n", status2);
> > +	send_stop = false;
> 
> ... and here.
Sure, will fix.

Thanks
>nvpublic
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c
index 1c8f708f212b..f1771beb75ea 100644
--- a/drivers/i2c/busses/i2c-nvidia-gpu.c
+++ b/drivers/i2c/busses/i2c-nvidia-gpu.c
@@ -169,6 +169,7 @@  static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
 {
 	struct gpu_i2c_dev *i2cd = i2c_get_adapdata(adap);
 	int status, status2;
+	bool send_stop = true;
 	int i, j;
 
 	/*
@@ -182,37 +183,42 @@  static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
 			/* gpu_i2c_read has implicit start */
 			status = gpu_i2c_read(i2cd, msgs[i].buf, msgs[i].len);
 			if (status < 0)
-				goto stop;
+				goto exit;
 		} else {
 			u8 addr = i2c_8bit_addr_from_msg(msgs + i);
 
 			status = gpu_i2c_start(i2cd);
 			if (status < 0) {
 				if (i == 0)
-					return status;
-				goto stop;
+					send_stop = false;
+				goto exit;
 			}
 
 			status = gpu_i2c_write(i2cd, addr);
 			if (status < 0)
-				goto stop;
+				goto exit;
 
 			for (j = 0; j < msgs[i].len; j++) {
 				status = gpu_i2c_write(i2cd, msgs[i].buf[j]);
 				if (status < 0)
-					goto stop;
+					goto exit;
 			}
 		}
 	}
 	status = gpu_i2c_stop(i2cd);
-	if (status < 0)
-		return status;
+	if (status < 0) {
+		send_stop = false;
+		goto exit;
+	}
 
-	return i;
-stop:
-	status2 = gpu_i2c_stop(i2cd);
-	if (status2 < 0)
-		dev_err(i2cd->dev, "i2c stop failed %d\n", status2);
+	send_stop = false;
+	status = i;
+exit:
+	if (send_stop) {
+		status2 = gpu_i2c_stop(i2cd);
+		if (status2 < 0)
+			dev_err(i2cd->dev, "i2c stop failed %d\n", status2);
+	}
 	return status;
 }