Skip to contentSkip to conversation

Fix unsigned return type

PATCH Applied Julia Lawall 3 participants 11 messages Sep 5, 2010 – Sep 7, 2010

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

cover Fix unsigned return type

These patches fix some cases where a negative constant is returned from a function that has an unsigned return type. In most cases, the result of every call to the function is stored in a signed variable, and thus the unsigned in the return type can just dropped.

#1 lore raw

PATCH 1/8 drivers/video/matrox/matroxfb_maven.c: Fix unsigned return type

The function has an unsigned return type, but returns a negative constant to indicate an error condition. The result of calling the function is only tested by comparison to 0, and thus unsigned is not needed and can be dropped from the return type.

A sematic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@exists@
identifier f;
constant C;
@@

unsigned f(...)
{ <+...
* return -C;
...+> }
// </smpl>

---
 drivers/video/matrox/matroxfb_maven.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/matrox/matroxfb_maven.c +1 -1
index 1e3e8f1..a78611a 100644
@@ -280,7 +280,7 @@ static int matroxfb_PLL_mavenclock(const struct matrox_pll_features2* pll,
 	return fxtal * (*feed) / (*in) * ctl->den;
 }
 
-static unsigned int matroxfb_mavenclock(const struct matrox_pll_ctl* ctl,
+static int matroxfb_mavenclock(const struct matrox_pll_ctl *ctl,
 		unsigned int htotal, unsigned int vtotal,
 		unsigned int* in, unsigned int* feed, unsigned int* post,
 		unsigned int* htotal2) {
#2 lore raw

PATCH 2/8 arch/x86/kernel/cpu/cpufreq: Fix unsigned return type

In reply to Julia Lawall

In each case, the function has an unsigned return type, but returns a negative constant to indicate an error condition. Each function is only called once. For nforce2_detect_chipset, the result is only compared to 0, and for longrun_determine_freqs, the result is stored in a variable of type (signed) int. Thus, for both functions, unsigned can be dropped from the return type.

A sematic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@exists@
identifier f;
constant C;
@@

unsigned f(...)
{ <+...
* return -C;
...+> }
// </smpl>

---
 arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c |    2 +-
 arch/x86/kernel/cpu/cpufreq/longrun.c         |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c +1 -1
index 733093d..141abeb 100644
@@ -393,7 +393,7 @@ static struct cpufreq_driver nforce2_driver = {
  * Detects nForce2 A2 and C1 stepping
  *
  */
-static unsigned int nforce2_detect_chipset(void)
+static int nforce2_detect_chipset(void)
 {
 	nforce2_dev = pci_get_subsys(PCI_VENDOR_ID_NVIDIA,
 					PCI_DEVICE_ID_NVIDIA_NFORCE2,
arch/x86/kernel/cpu/cpufreq/longrun.c +1 -1
index fc09f14..77945bf 100644
@@ -165,7 +165,7 @@ static unsigned int longrun_get(unsigned int cpu)
  * TMTA rules:
  * performance_pctg = (target_freq - low_freq)/(high_freq - low_freq)
  */
-static unsigned int __cpuinit longrun_determine_freqs(unsigned int *low_freq,
+static int __cpuinit longrun_determine_freqs(unsigned int *low_freq,
 						      unsigned int *high_freq)
 {
 	u32 msr_lo, msr_hi;
#3 lore raw

PATCH 3/8 net/9p/trans_fd.c: Fix unsigned return type

In reply to Julia Lawall

The function has an unsigned return type, but returns a negative constant to indicate an error condition. The result of calling the function is always stored in a variable of type (signed) int, and thus unsigned can be dropped from the return type.

A sematic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@exists@
identifier f;
constant C;
@@

unsigned f(...)
{ <+...
* return -C;
...+> }
// </smpl>

---
 net/9p/trans_fd.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/9p/trans_fd.c +1 -1
index c85109d..078eb16 100644
@@ -222,7 +222,7 @@ static void p9_conn_cancel(struct p9_conn *m, int err)
 	}
 }
 
-static unsigned int
+static int
 p9_fd_poll(struct p9_client *client, struct poll_table_struct *pt)
 {
 	int ret, n;
maintainer Applied
#4 lore raw

Re: [PATCH 3/8] net/9p/trans_fd.c: Fix unsigned return type

From: Julia Lawall <[email protected]>
Date: Sun, 5 Sep 2010 21:00:21 +0200

Quoted 7 lines

The function has an unsigned return type, but returns a negative constant to indicate an error condition. The result of calling the function is always stored in a variable of type (signed) int, and thus unsigned can be dropped from the return type.

A sematic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

...

Quoted 1 line

Applied.

#5 lore raw

PATCH 4/8 drivers/i2c/busses/i2c-pasemi.c: Fix unsigned return type

In reply to Julia Lawall

The function has an unsigned return type, but returns a negative constant to indicate an error condition. The result of calling the function is always stored in a variable of type (signed) int, and thus unsigned can be dropped from the return type.

A sematic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@exists@
identifier f;
constant C;
@@

unsigned f(...)
{ <+...
* return -C;
...+> }
// </smpl>

---
 drivers/i2c/busses/i2c-pasemi.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-pasemi.c +1 -1
index 4174101..837b8c1 100644
@@ -88,7 +88,7 @@ static void pasemi_smb_clear(struct pasemi_smbus *smbus)
 	reg_write(smbus, REG_SMSTA, status);
 }
 
-static unsigned int pasemi_smb_waitready(struct pasemi_smbus *smbus)
+static int pasemi_smb_waitready(struct pasemi_smbus *smbus)
 {
 	int timeout = 10;
 	unsigned int status;
Acked-by on v1 4/8
#6 lore raw

Re: [PATCH 4/8] drivers/i2c/busses/i2c-pasemi.c: Fix unsigned return type

Quoted 14 lines · Julia Lawall

The function has an unsigned return type, but returns a negative constant to indicate an error condition. The result of calling the function is always stored in a variable of type (signed) int, and thus unsigned can be dropped from the return type.

A sematic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@exists@
identifier f;
constant C;
@@

Quoted 7 lines

unsigned f(...)
{ <+...
* return -C;
...+> }
// </smpl>

#7 lore raw

PATCH 5/8 drivers/atm/firestream.c: Fix unsigned return type

In reply to Julia Lawall

The function has an unsigned return type, but returns a negative constant to indicate an error condition. The result of calling the function is always stored in a variable of type (signed) int, and thus unsigned can be dropped from the return type.

A sematic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@exists@
identifier f;
constant C;
@@

unsigned f(...)
{ <+...
* return -C;
...+> }
// </smpl>

---
 drivers/atm/firestream.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/atm/firestream.c +2 -2
index 8717809..1af977e 100644
@@ -444,8 +444,8 @@ static inline void fs_kfree_skb (struct sk_buff * skb)
 #define ROUND_NEAREST 3
 /********** make rate (not quite as much fun as Horizon) **********/
 
-static unsigned int make_rate (unsigned int rate, int r,
-			       u16 * bits, unsigned int * actual) 
+static int make_rate(unsigned int rate, int r,
+		      u16 *bits, unsigned int *actual)
 {
 	unsigned char exp = -1; /* hush gcc */
 	unsigned int man = -1;  /* hush gcc */
maintainer Applied
#8 lore raw

Re: [PATCH 5/8] drivers/atm/firestream.c: Fix unsigned return type

From: Julia Lawall <[email protected]>
Date: Sun, 5 Sep 2010 21:00:23 +0200

Quoted 7 lines

The function has an unsigned return type, but returns a negative constant to indicate an error condition. The result of calling the function is always stored in a variable of type (signed) int, and thus unsigned can be dropped from the return type.

A sematic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

...

Quoted 1 line

Applied.

#9 lore raw

PATCH 6/8 drivers/staging/comedi/drivers: Fix unsigned return type

In reply to Julia Lawall

In each case, the function has an unsigned return type, but returns a negative constant to indicate an error condition. For move_block_from_dma, there is only one call and the return value is dropped, so it need not be unsigned. For labpc_eeprom_write, there is only one call and the result is stored in a signed variable, so again the unsigned return type is not necessary.

A sematic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@exists@
identifier f;
constant C;
@@

unsigned f(...)
{ <+...
* return -C;
...+> }
// </smpl>

---
 drivers/staging/comedi/drivers/adl_pci9118.c |    2 +-
 drivers/staging/comedi/drivers/ni_labpc.c    |    6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/staging/comedi/drivers/adl_pci9118.c +1 -1
index a2bd4e6..cb2843d 100644
@@ -634,7 +634,7 @@ static unsigned int defragment_dma_buffer(struct comedi_device *dev,
 /*
 ==============================================================================
 */
-static unsigned int move_block_from_dma(struct comedi_device *dev,
+static int move_block_from_dma(struct comedi_device *dev,
 					struct comedi_subdevice *s,
 					short *dma_buffer,
 					unsigned int num_samples)
drivers/staging/comedi/drivers/ni_labpc.c +3 -3
index 3acf7e6..19f79e8 100644
@@ -250,7 +250,7 @@ static unsigned int labpc_serial_in(struct comedi_device *dev);
 static unsigned int labpc_eeprom_read(struct comedi_device *dev,
 				      unsigned int address);
 static unsigned int labpc_eeprom_read_status(struct comedi_device *dev);
-static unsigned int labpc_eeprom_write(struct comedi_device *dev,
+static int labpc_eeprom_write(struct comedi_device *dev,
 				       unsigned int address,
 				       unsigned int value);
 static void write_caldac(struct comedi_device *dev, unsigned int channel,
@@ -1986,8 +1986,8 @@ static unsigned int labpc_eeprom_read(struct comedi_device *dev,
 	return value;
 }
 
-static unsigned int labpc_eeprom_write(struct comedi_device *dev,
-				       unsigned int address, unsigned int value)
+static int labpc_eeprom_write(struct comedi_device *dev,
+				unsigned int address, unsigned int value)
 {
 	const int write_enable_instruction = 0x6;
 	const int write_instruction = 0x2;
#10 lore raw

PATCH 8/8 drivers/net/wireless/iwlwifi/iwl-agn.c: Fix return value from an unsigned function

In reply to Julia Lawall

The function has an unsigned return type, but returns a negative constant to indicate an error condition. Another error condition in the same function is indicated by returning 0, and indeed the only call to the function checks for 0 to detect errors, so the return of a negative value it converted to a return of 0.

A sematic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@exists@
identifier f;
constant C;
@@

unsigned f(...)
{ <+...
* return -C;
...+> }
// </smpl>

---
 drivers/net/wireless/iwlwifi/iwl-agn.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/iwlwifi/iwl-agn.c +1 -1
index ad0e67f..86b55c2 100644
@@ -369,7 +369,7 @@ static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
 
 	if (!priv->beacon_ctx) {
 		IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
-		return -EINVAL;
+		return 0;
 	}
 
 	/* Initialize memory */