Skip to contentSkip to conversation

firmware: arm_scpi: drop unnecessary type cast to scpi_shared_mem

PATCH New Sudeep Holla 2 participants 8 messages Oct 5, 2017 – Oct 6, 2017 System control & power/management interface (SCPI/SCMI) Message Protocol drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 firmware: arm_scpi: drop unnecessary type cast to scpi_shared_mem

This patch drops the only present type cast of the SCPI payload pointer to scpi_shared_mem inorder to align with other occurrences, IOW for consistency.

Cc Heiner Kallweit <[email protected]>
---
 drivers/firmware/arm_scpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/arm_scpi.c +1 -1
index c923d1ebfa3e..a888970f1347 100644
@@ -453,7 +453,7 @@ static void scpi_tx_prepare(struct mbox_client *c, void *msg)
 	unsigned long flags;
 	struct scpi_xfer *t = msg;
 	struct scpi_chan *ch = container_of(c, struct scpi_chan, cl);
-	struct scpi_shared_mem *mem = (struct scpi_shared_mem *)ch->tx_payload;
+	struct scpi_shared_mem *mem = ch->tx_payload;
 
 	if (t->tx_buf) {
 		if (scpi_info->is_legacy)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/2 firmware: arm_scpi: remove all single element structures

Both clk_get_value and sensor_value structures contains a single element and hence needs no packing making the whole structure defination unnecessary.

This patch gets rid of both those structures

Cc Heiner Kallweit <[email protected]>
---
 drivers/firmware/arm_scpi.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)
drivers/firmware/arm_scpi.c +7 -15
index a888970f1347..f0c37a4ecddf 100644
@@ -304,10 +304,6 @@ struct clk_get_info {
 	u8 name[20];
 } __packed;
 
-struct clk_get_value {
-	__le32 rate;
-} __packed;
-
 struct clk_set_value {
 	__le16 id;
 	__le16 reserved;
@@ -346,10 +342,6 @@ struct _scpi_sensor_info {
 	char name[20];
 };
 
-struct sensor_value {
-	__le64 val;
-};
-
 struct dev_pstate_set {
 	__le16 dev_id;
 	u8 pstate;
@@ -577,13 +569,13 @@ scpi_clk_get_range(u16 clk_id, unsigned long *min, unsigned long *max)
 static unsigned long scpi_clk_get_val(u16 clk_id)
 {
 	int ret;
-	struct clk_get_value clk;
+	__le32 rate;
 	__le16 le_clk_id = cpu_to_le16(clk_id);
 
 	ret = scpi_send_message(CMD_GET_CLOCK_VALUE, &le_clk_id,
-				sizeof(le_clk_id), &clk, sizeof(clk));
+				sizeof(le_clk_id), &rate, sizeof(rate));
 
-	return ret ? ret : le32_to_cpu(clk.rate);
+	return ret ? ret : le32_to_cpu(rate);
 }
 
 static int scpi_clk_set_val(u16 clk_id, unsigned long rate)
@@ -775,19 +767,19 @@ static int scpi_sensor_get_info(u16 sensor_id, struct scpi_sensor_info *info)
 static int scpi_sensor_get_value(u16 sensor, u64 *val)
 {
 	__le16 id = cpu_to_le16(sensor);
-	struct sensor_value buf;
+	__le64 value;
 	int ret;
 
 	ret = scpi_send_message(CMD_SENSOR_VALUE, &id, sizeof(id),
-				&buf, sizeof(buf));
+				&value, sizeof(value));
 	if (ret)
 		return ret;
 
 	if (scpi_info->is_legacy)
 		/* only 32-bits supported, upper 32 bits can be junk */
-		*val = le32_to_cpup((__le32 *)&buf.val);
+		*val = le32_to_cpup((__le32 *)&value);
 	else
-		*val = le64_to_cpu(buf.val);
+		*val = le64_to_cpu(value);
 
 	return 0;
 }
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/2 firmware: arm_scpi: remove all single element structures

Am 05.10.2017 um 13:11 schrieb Sudeep Holla:

Quoted 70 lines

Both clk_get_value and sensor_value structures contains a single element and hence needs no packing making the whole structure defination unnecessary.

This patch gets rid of both those structures

Cc Heiner Kallweit <[email protected]>
---
 drivers/firmware/arm_scpi.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)
drivers/firmware/arm_scpi.c +5 -13
index a888970f1347..f0c37a4ecddf 100644
@@ -304,10 +304,6 @@ struct clk_get_info {
 	u8 name[20];
 } __packed;
 
-struct clk_get_value {
-	__le32 rate;
-} __packed;
-
 struct clk_set_value {
 	__le16 id;
 	__le16 reserved;
@@ -346,10 +342,6 @@ struct _scpi_sensor_info {
 	char name[20];
 };
 
-struct sensor_value {
-	__le64 val;
-};
-
 struct dev_pstate_set {
 	__le16 dev_id;
 	u8 pstate;
@@ -577,13 +569,13 @@ scpi_clk_get_range(u16 clk_id, unsigned long *min, unsigned long *max)
 static unsigned long scpi_clk_get_val(u16 clk_id)
 {
 	int ret;
-	struct clk_get_value clk;
+	__le32 rate;
 	__le16 le_clk_id = cpu_to_le16(clk_id);
 
 	ret = scpi_send_message(CMD_GET_CLOCK_VALUE, &le_clk_id,
-				sizeof(le_clk_id), &clk, sizeof(clk));
+				sizeof(le_clk_id), &rate, sizeof(rate));
 
-	return ret ? ret : le32_to_cpu(clk.rate);
+	return ret ? ret : le32_to_cpu(rate);
 }
 
 static int scpi_clk_set_val(u16 clk_id, unsigned long rate)
@@ -775,19 +767,19 @@ static int scpi_sensor_get_info(u16 sensor_id, struct scpi_sensor_info *info)
 static int scpi_sensor_get_value(u16 sensor, u64 *val)
 {
 	__le16 id = cpu_to_le16(sensor);
-	struct sensor_value buf;
+	__le64 value;
 	int ret;
 
 	ret = scpi_send_message(CMD_SENSOR_VALUE, &id, sizeof(id),
-				&buf, sizeof(buf));
+				&value, sizeof(value));
 	if (ret)
 		return ret;
 

drivers/firmware/arm_scpi.c static int scpi_sensor_get_info(u16 sensor_id, struct scpi_sensor_info *info) · line 785

Quoted 10 lines
drivers/firmware/arm_scpi.c +2 -2
 	if (scpi_info->is_legacy)
 		/* only 32-bits supported, upper 32 bits can be junk */
-		*val = le32_to_cpup((__le32 *)&buf.val);
+		*val = le32_to_cpup((__le32 *)&value);
 	else
-		*val = le64_to_cpu(buf.val);
+		*val = le64_to_cpu(value);
 
 	return 0;
 }

Looks good to me.

#3 lore raw

PATCH 2/2 firmware: arm_scpi: remove all single element structures

Quoted 9 lines · Heiner Kallweit

Am 05.10.2017 um 13:11 schrieb Sudeep Holla:

Quoted 8 lines

Both clk_get_value and sensor_value structures contains a single element and hence needs no packing making the whole structure defination unnecessary.

This patch gets rid of both those structures

Cc Heiner Kallweit <[email protected]>

[..]

Quoted 2 lines
Quoted 1 line

Looks good to me.

Thanks. Tested-by or Reviewed-by would help ;)

Signature · 2 lines
Regards,
Sudeep
#4 lore raw

PATCH 2/2 firmware: arm_scpi: remove all single element structures

Am 06.10.2017 um 10:53 schrieb Sudeep Holla:

Quoted 13 lines · Heiner Kallweit
Quoted 9 lines

Am 05.10.2017 um 13:11 schrieb Sudeep Holla:

Quoted 8 lines

Both clk_get_value and sensor_value structures contains a single element and hence needs no packing making the whole structure defination unnecessary.

This patch gets rid of both those structures

Cc Heiner Kallweit <[email protected]>
Quoted 8 lines

[..]

Quoted 2 lines
Quoted 1 line

Looks good to me.

Thanks. Tested-by or Reviewed-by would help ;)

#5 lore raw

PATCH 1/2 firmware: arm_scpi: drop unnecessary type cast to scpi_shared_mem

In reply to Sudeep Holla

Am 05.10.2017 um 13:11 schrieb Sudeep Holla:

Quoted 15 lines

This patch drops the only present type cast of the SCPI payload pointer to scpi_shared_mem inorder to align with other occurrences, IOW for consistency.

Cc Heiner Kallweit <[email protected]>
---
 drivers/firmware/arm_scpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/arm_scpi.c +0 -0
index c923d1ebfa3e..a888970f1347 100644

drivers/firmware/arm_scpi.c static void scpi_tx_prepare(struct mbox_client *c, void *msg) · line 457

Quoted 6 lines
drivers/firmware/arm_scpi.c +1 -1
@@ -453,7 +453,7 @@ static void scpi_tx_prepare(struct mbox_client *c, void *msg)
 	unsigned long flags;
 	struct scpi_xfer *t = msg;
 	struct scpi_chan *ch = container_of(c, struct scpi_chan, cl);
-	struct scpi_shared_mem *mem = (struct scpi_shared_mem *)ch->tx_payload;
+	struct scpi_shared_mem *mem = ch->tx_payload;
 

This should work fine, however it might not be 100% clean with regard to __iomem annotation. ch->tx_payload is of type "void __iomem *" and I would assume that sparse complains about the new statement.
The old one casts away the __iomem, what isn't much better IMO.

By the way, I think this also applies to other places in this driver where ch->rx/tx_payload are used.

Quoted 3 lines
drivers/firmware/arm_scpi.c +0 -0
 	if (t->tx_buf) {
 		if (scpi_info->is_legacy)
#6 lore raw

PATCH 1/2 firmware: arm_scpi: drop unnecessary type cast to scpi_shared_mem

Quoted 11 lines · Heiner Kallweit

Am 05.10.2017 um 13:11 schrieb Sudeep Holla:

Quoted 10 lines

This patch drops the only present type cast of the SCPI payload pointer to scpi_shared_mem inorder to align with other occurrences, IOW for consistency.

Cc Heiner Kallweit <[email protected]>
---
 drivers/firmware/arm_scpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

drivers/firmware/arm_scpi.c static void scpi_tx_prepare(struct mbox_client *c, void *msg) · line 457

Quoted 11 lines
drivers/firmware/arm_scpi.c +1 -1
index c923d1ebfa3e..a888970f1347 100644
@@ -453,7 +453,7 @@ static void scpi_tx_prepare(struct mbox_client *c, void *msg)
 	unsigned long flags;
 	struct scpi_xfer *t = msg;
 	struct scpi_chan *ch = container_of(c, struct scpi_chan, cl);
-	struct scpi_shared_mem *mem = (struct scpi_shared_mem *)ch->tx_payload;
+	struct scpi_shared_mem *mem = ch->tx_payload;
 

This should work fine, however it might not be 100% clean with regard to __iomem annotation. ch->tx_payload is of type "void __iomem *" and I would assume that sparse complains about the new statement.

Yes sparse complains for both(with or without typecast)

Quoted 2 lines

The old one casts away the __iomem, what isn't much better IMO.

Agreed.

Quoted 3 lines

By the way, I think this also applies to other places in this driver where ch->rx/tx_payload are used.

Yes, but do you have any alternatives in your mind ? I am happy to hear that.

Signature · 2 lines
Regards,
Sudeep
#7 lore raw

PATCH 1/2 firmware: arm_scpi: drop unnecessary type cast to scpi_shared_mem

Am 06.10.2017 um 10:51 schrieb Sudeep Holla:

Quoted 34 lines · Heiner Kallweit
Quoted 11 lines

Am 05.10.2017 um 13:11 schrieb Sudeep Holla:

Quoted 10 lines

This patch drops the only present type cast of the SCPI payload pointer to scpi_shared_mem inorder to align with other occurrences, IOW for consistency.

Cc Heiner Kallweit <[email protected]>
---
 drivers/firmware/arm_scpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

drivers/firmware/arm_scpi.c static void scpi_tx_prepare(struct mbox_client *c, void *msg) · line 457

Quoted 11 lines
drivers/firmware/arm_scpi.c +1 -1
index c923d1ebfa3e..a888970f1347 100644
@@ -453,7 +453,7 @@ static void scpi_tx_prepare(struct mbox_client *c, void *msg)
 	unsigned long flags;
 	struct scpi_xfer *t = msg;
 	struct scpi_chan *ch = container_of(c, struct scpi_chan, cl);
-	struct scpi_shared_mem *mem = (struct scpi_shared_mem *)ch->tx_payload;
+	struct scpi_shared_mem *mem = ch->tx_payload;
 

This should work fine, however it might not be 100% clean with regard to __iomem annotation. ch->tx_payload is of type "void __iomem *" and I would assume that sparse complains about the new statement.

Yes sparse complains for both(with or without typecast)

Quoted 2 lines

The old one casts away the __iomem, what isn't much better IMO.

Quoted 9 lines

Agreed.

Quoted 3 lines

By the way, I think this also applies to other places in this driver where ch->rx/tx_payload are used.

Yes, but do you have any alternatives in your mind ? I am happy to hear that.

I'll send a patch addressing this issue.