Skip to contentSkip to conversation

i2c-hid: explicitly cast parametrs to follow specifiers

PATCH In review Andy Shevchenko 2 participants 4 messages Jun 25, 2013 – Sep 4, 2013 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c-hid: explicitly cast parametrs to follow specifiers

The vendor and product parameters are defined as __u32, but used as short int. Let's do an explicit casting for them.

---
 drivers/hid/i2c-hid/i2c-hid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/i2c-hid/i2c-hid.c +1 -1
index 879b0ed..d595f2a 100644
@@ -1009,7 +1009,7 @@ static int i2c_hid_probe(struct i2c_client *client,
 	hid->product = le16_to_cpu(ihid->hdesc.wProductID);
 
 	snprintf(hid->name, sizeof(hid->name), "%s %04hX:%04hX",
-		 client->name, hid->vendor, hid->product);
+		 client->name, (short int)hid->vendor, (short int)hid->product);
 
 	ret = hid_add_device(hid);
 	if (ret) {
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 2 lines · Andy Shevchenko

The vendor and product parameters are defined as __u32, but used as short int. Let's do an explicit casting for them.

Jiri, Benjamin, any comment on this?

Quoted 19 lines
---
 drivers/hid/i2c-hid/i2c-hid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/i2c-hid/i2c-hid.c +1 -1
index 879b0ed..d595f2a 100644
@@ -1009,7 +1009,7 @@ static int i2c_hid_probe(struct i2c_client *client,
 	hid->product = le16_to_cpu(ihid->hdesc.wProductID);
 
 	snprintf(hid->name, sizeof(hid->name), "%s %04hX:%04hX",
-		 client->name, hid->vendor, hid->product);
+		 client->name, (short int)hid->vendor, (short int)hid->product);
 
 	ret = hid_add_device(hid);
 	if (ret) {
Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#2 lore raw
In reply to Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

The vendor and product parameters are defined as __u32, but used as short int. Let's do an explicit casting for them.

Is this fixing any compiler warning you have seen?

Quoted 22 lines
---
 drivers/hid/i2c-hid/i2c-hid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/i2c-hid/i2c-hid.c +1 -1
index 879b0ed..d595f2a 100644
@@ -1009,7 +1009,7 @@ static int i2c_hid_probe(struct i2c_client *client,
 	hid->product = le16_to_cpu(ihid->hdesc.wProductID);
 
 	snprintf(hid->name, sizeof(hid->name), "%s %04hX:%04hX",
-		 client->name, hid->vendor, hid->product);
+		 client->name, (short int)hid->vendor, (short int)hid->product);
 
 	ret = hid_add_device(hid);
 	if (ret) {
Signature · 1 line
1.8.3.1
Signature · 2 lines
Jiri Kosina
SUSE Labs
#3 lore raw
Quoted 6 lines · Jiri Kosina
Quoted 2 lines · Andy Shevchenko

The vendor and product parameters are defined as __u32, but used as short int. Let's do an explicit casting for them.

Is this fixing any compiler warning you have seen?

It was found by static analyzer.

Quoted 14 lines
Quoted 14 lines
---
 drivers/hid/i2c-hid/i2c-hid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/i2c-hid/i2c-hid.c +0 -0
index 879b0ed..d595f2a 100644
@@ -1009,7 +1009,7 @@ static int i2c_hid_probe(struct i2c_client *client,
 	hid->product = le16_to_cpu(ihid->hdesc.wProductID);
 
Quoted 3 lines

drivers/hid/i2c-hid/i2c-hid.c static int i2c_hid_probe(struct i2c_client *client, · line 1012

Quoted 3 lines
drivers/hid/i2c-hid/i2c-hid.c +1 -1
 	snprintf(hid->name, sizeof(hid->name), "%s %04hX:%04hX",
-		 client->name, hid->vendor, hid->product);
+		 client->name, (short int)hid->vendor, (short int)hid->product);

...and it's probably better to use (unsigned short int) if this patch is going anywhere.

Quoted 7 lines
Quoted 6 lines
drivers/hid/i2c-hid/i2c-hid.c +0 -0
 	ret = hid_add_device(hid);
 	if (ret) {
Signature · 1 line
1.8.3.1
Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy