Skip to contentSkip to conversation

usb: typec: ucsi: ccg: Adjustments for common code in two functions

PATCH In review Markus Elfring 4 participants 10 messages Sep 25, 2024 – Sep 26, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover usb: typec: ucsi: ccg: Adjustments for common code in two functions

From: Markus Elfring <[email protected]>
Date: Wed, 25 Sep 2024 19:19:01 +0200

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Use common code in ccg_write()
Use common code in ccg_read()

 drivers/usb/typec/ucsi/ucsi_ccg.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

--
2.46.1

#1 lore raw

PATCH 1/2 usb: typec: ucsi: ccg: Use common code in ccg_write()

From: Markus Elfring <[email protected]>
Date: Wed, 25 Sep 2024 19:00:23 +0200

Add a label so that three statements can be better reused at the end of this function implementation.

This issue was detected by using the Coccinelle software.

---
 drivers/usb/typec/ucsi/ucsi_ccg.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/typec/ucsi/ucsi_ccg.c +4 -4
index b3ec799fc873..ed075a403d87 100644
@@ -306,14 +306,14 @@ static int ccg_write(struct ucsi_ccg *uc, u16 rab, const u8 *data, u32 len)
 	status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
 	if (status < 0) {
 		dev_err(uc->dev, "i2c_transfer failed %d\n", status);
-		pm_runtime_put_sync(uc->dev);
-		kfree(buf);
-		return status;
+		goto put_sync;
 	}
 
+	status = 0;
+put_sync:
 	pm_runtime_put_sync(uc->dev);
 	kfree(buf);
-	return 0;
+	return status;
 }
 
 static int ccg_op_region_update(struct ucsi_ccg *uc, u32 cci)

--
2.46.1

maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] usb: typec: ucsi: ccg: Use common code in ccg_write()

Quoted 9 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 25 Sep 2024 19:00:23 +0200

Add a label so that three statements can be better reused at the end of this function implementation.

This issue was detected by using the Coccinelle software.

Quoted 29 lines
---
 drivers/usb/typec/ucsi/ucsi_ccg.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/typec/ucsi/ucsi_ccg.c +4 -5
index b3ec799fc873..ed075a403d87 100644
@@ -306,14 +306,14 @@ static int ccg_write(struct ucsi_ccg *uc, u16 rab, const u8 *data, u32 len)
 	status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
 	if (status < 0) {
 		dev_err(uc->dev, "i2c_transfer failed %d\n", status);
-		pm_runtime_put_sync(uc->dev);
-		kfree(buf);
-		return status;
+		goto put_sync;
 	}
 
+	status = 0;
+put_sync:
 	pm_runtime_put_sync(uc->dev);
 	kfree(buf);
-	return 0;
+	return status;
 }
 
 static int ccg_op_region_update(struct ucsi_ccg *uc, u32 cci)
--

2.46.1

Signature · 1 line
heikki
#3 lore raw

PATCH 2/2 usb: typec: ucsi: ccg: Use common code in ccg_read()

In reply to Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 25 Sep 2024 19:08:07 +0200

Add a label so that two statements can be better reused at the end of this function implementation.

---
 drivers/usb/typec/ucsi/ucsi_ccg.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/usb/typec/ucsi/ucsi_ccg.c +4 -3
index ed075a403d87..e3850c42583e 100644
@@ -269,15 +269,16 @@ static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len)
 		status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
 		if (status < 0) {
 			dev_err(uc->dev, "i2c_transfer failed %d\n", status);
-			pm_runtime_put_sync(uc->dev);
-			return status;
+			goto put_sync;
 		}
 		rab += rlen;
 		rem_len -= rlen;
 	}
 
+	status = 0;
+put_sync:
 	pm_runtime_put_sync(uc->dev);
-	return 0;
+	return status;
 }
 
 static int ccg_write(struct ucsi_ccg *uc, u16 rab, const u8 *data, u32 len)

--
2.46.1

maintainer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] usb: typec: ucsi: ccg: Use common code in ccg_read()

Quoted 7 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 25 Sep 2024 19:08:07 +0200

Add a label so that two statements can be better reused at the end of this function implementation.

Quoted 30 lines
---
 drivers/usb/typec/ucsi/ucsi_ccg.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/usb/typec/ucsi/ucsi_ccg.c +4 -4
index ed075a403d87..e3850c42583e 100644
@@ -269,15 +269,16 @@ static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len)
 		status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
 		if (status < 0) {
 			dev_err(uc->dev, "i2c_transfer failed %d\n", status);
-			pm_runtime_put_sync(uc->dev);
-			return status;
+			goto put_sync;
 		}
 		rab += rlen;
 		rem_len -= rlen;
 	}
 
+	status = 0;
+put_sync:
 	pm_runtime_put_sync(uc->dev);
-	return 0;
+	return status;
 }
 
 static int ccg_write(struct ucsi_ccg *uc, u16 rab, const u8 *data, u32 len)
--

2.46.1

Signature · 1 line
heikki
Acked-by on the v1 series
#5 lore raw
In reply to Markus Elfring
Quoted 6 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 25 Sep 2024 19:19:01 +0200

A few update suggestions were taken into account
from static source code analysis.

Quoted 6 lines

Markus Elfring (2):
Use common code in ccg_write()
Use common code in ccg_read()

 drivers/usb/typec/ucsi/ucsi_ccg.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

For the series:

Signature · 2 lines
With best wishes
Dmitry
#6 lore raw
Quoted 11 lines · Dmitry Baryshkov
Quoted 10 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 25 Sep 2024 19:19:01 +0200

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Use common code in ccg_write()
Use common code in ccg_read()

Quoted 6 lines
Quoted 2 lines
 drivers/usb/typec/ucsi/ucsi_ccg.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

For the series:

I believe there is no-one to take it, but in any case the thing is that kfree() probably can be done using __free(). Then PM runtime handled differently.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Dmitry Baryshkov
Quoted 10 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 25 Sep 2024 19:19:01 +0200

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Use common code in ccg_write()
Use common code in ccg_read()

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
 drivers/usb/typec/ucsi/ucsi_ccg.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

For the series:

I believe there is no-one to take it,

I guessed so.

Quoted 2 lines

but in any case the thing is that kfree()
probably can be done using __free(). Then PM runtime handled differently.

That's a separate cleanup in my opinion.

Signature · 2 lines
With best wishes
Dmitry
#8 lore raw
Quoted 3 lines · Dmitry Baryshkov
Quoted 1 line · Andy Shevchenko

On Thu, Sep 26, 2024 at 12:26:24AM +0300, Dmitry Baryshkov wrote:

...

Quoted 4 lines
Quoted 2 lines

but in any case the thing is that kfree()
probably can be done using __free(). Then PM runtime handled differently.

That's a separate cleanup in my opinion.

Yes and for that we do not need an intermediate change, right?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · Dmitry Baryshkov
Quoted 1 line · Andy Shevchenko

On Thu, Sep 26, 2024 at 12:26:24AM +0300, Dmitry Baryshkov wrote:

Quoted 8 lines

...

Quoted 4 lines
Quoted 2 lines

but in any case the thing is that kfree()
probably can be done using __free(). Then PM runtime handled differently.

That's a separate cleanup in my opinion.

Yes and for that we do not need an intermediate change, right?

I don't have a strong opinion here (and I don't feel a strong need to move existing code into using cleanup.h just for the sake of it).

Signature · 2 lines
With best wishes
Dmitry