* [PATCH 0/8] Fix unsigned return type
@ 2010-09-05 18:59 Julia Lawall
2010-09-05 19:00 ` [PATCH 1/8] drivers/video/matrox/matroxfb_maven.c: " Julia Lawall
` (6 more replies)
0 siblings, 7 replies; 11+ messages in thread
From: Julia Lawall @ 2010-09-05 18:59 UTC (permalink / raw)
To: linux-kernel; +Cc: kernel-janitors
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.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/8] drivers/video/matrox/matroxfb_maven.c: Fix unsigned return type
2010-09-05 18:59 [PATCH 0/8] Fix unsigned return type Julia Lawall
@ 2010-09-05 19:00 ` Julia Lawall
2010-09-05 19:00 ` [PATCH 2/8] arch/x86/kernel/cpu/cpufreq: " Julia Lawall
` (5 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Julia Lawall @ 2010-09-05 19:00 UTC (permalink / raw)
To: Petr Vandrovec; +Cc: kernel-janitors, linux-fbdev, linux-kernel
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>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
drivers/video/matrox/matroxfb_maven.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/video/matrox/matroxfb_maven.c b/drivers/video/matrox/matroxfb_maven.c
index 1e3e8f1..a78611a 100644
--- a/drivers/video/matrox/matroxfb_maven.c
+++ b/drivers/video/matrox/matroxfb_maven.c
@@ -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) {
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/8] arch/x86/kernel/cpu/cpufreq: Fix unsigned return type
2010-09-05 18:59 [PATCH 0/8] Fix unsigned return type Julia Lawall
2010-09-05 19:00 ` [PATCH 1/8] drivers/video/matrox/matroxfb_maven.c: " Julia Lawall
@ 2010-09-05 19:00 ` Julia Lawall
2010-09-05 19:00 ` [PATCH 3/8] net/9p/trans_fd.c: " Julia Lawall
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Julia Lawall @ 2010-09-05 19:00 UTC (permalink / raw)
To: Dave Jones
Cc: kernel-janitors, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
x86, cpufreq, linux-kernel
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>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c | 2 +-
arch/x86/kernel/cpu/cpufreq/longrun.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c b/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c
index 733093d..141abeb 100644
--- a/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c
+++ b/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c
@@ -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,
diff --git a/arch/x86/kernel/cpu/cpufreq/longrun.c b/arch/x86/kernel/cpu/cpufreq/longrun.c
index fc09f14..77945bf 100644
--- a/arch/x86/kernel/cpu/cpufreq/longrun.c
+++ b/arch/x86/kernel/cpu/cpufreq/longrun.c
@@ -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;
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/8] net/9p/trans_fd.c: Fix unsigned return type
2010-09-05 18:59 [PATCH 0/8] Fix unsigned return type Julia Lawall
2010-09-05 19:00 ` [PATCH 1/8] drivers/video/matrox/matroxfb_maven.c: " Julia Lawall
2010-09-05 19:00 ` [PATCH 2/8] arch/x86/kernel/cpu/cpufreq: " Julia Lawall
@ 2010-09-05 19:00 ` Julia Lawall
2010-09-07 1:39 ` David Miller
2010-09-05 19:00 ` [PATCH 4/8] drivers/i2c/busses/i2c-pasemi.c: " Julia Lawall
` (3 subsequent siblings)
6 siblings, 1 reply; 11+ messages in thread
From: Julia Lawall @ 2010-09-05 19:00 UTC (permalink / raw)
To: David S. Miller; +Cc: kernel-janitors, netdev, linux-kernel
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>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
net/9p/trans_fd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
index c85109d..078eb16 100644
--- a/net/9p/trans_fd.c
+++ b/net/9p/trans_fd.c
@@ -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;
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/8] drivers/i2c/busses/i2c-pasemi.c: Fix unsigned return type
2010-09-05 18:59 [PATCH 0/8] Fix unsigned return type Julia Lawall
` (2 preceding siblings ...)
2010-09-05 19:00 ` [PATCH 3/8] net/9p/trans_fd.c: " Julia Lawall
@ 2010-09-05 19:00 ` Julia Lawall
2010-09-06 16:30 ` [PATCH 4/8] drivers/i2c/busses/i2c-pasemi.c: Fix unsigned Olof Johansson
2010-09-05 19:00 ` [PATCH 5/8] drivers/atm/firestream.c: Fix unsigned return type Julia Lawall
` (2 subsequent siblings)
6 siblings, 1 reply; 11+ messages in thread
From: Julia Lawall @ 2010-09-05 19:00 UTC (permalink / raw)
To: Olof Johansson
Cc: kernel-janitors, linux-kernel, linux-i2c,
Ben Dooks (embedded platforms), Jean Delvare (PC drivers, core),
linuxppc-dev
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>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
drivers/i2c/busses/i2c-pasemi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c
index 4174101..837b8c1 100644
--- a/drivers/i2c/busses/i2c-pasemi.c
+++ b/drivers/i2c/busses/i2c-pasemi.c
@@ -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;
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 5/8] drivers/atm/firestream.c: Fix unsigned return type
2010-09-05 18:59 [PATCH 0/8] Fix unsigned return type Julia Lawall
` (3 preceding siblings ...)
2010-09-05 19:00 ` [PATCH 4/8] drivers/i2c/busses/i2c-pasemi.c: " Julia Lawall
@ 2010-09-05 19:00 ` Julia Lawall
2010-09-07 1:40 ` David Miller
2010-09-05 19:00 ` [PATCH 6/8] drivers/staging/comedi/drivers: " Julia Lawall
2010-09-05 19:00 ` [PATCH 8/8] drivers/net/wireless/iwlwifi/iwl-agn.c: Fix return value from an unsigned function Julia Lawall
6 siblings, 1 reply; 11+ messages in thread
From: Julia Lawall @ 2010-09-05 19:00 UTC (permalink / raw)
To: Chas Williams; +Cc: kernel-janitors, linux-atm-general, netdev, linux-kernel
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>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
drivers/atm/firestream.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
index 8717809..1af977e 100644
--- a/drivers/atm/firestream.c
+++ b/drivers/atm/firestream.c
@@ -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 */
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 6/8] drivers/staging/comedi/drivers: Fix unsigned return type
2010-09-05 18:59 [PATCH 0/8] Fix unsigned return type Julia Lawall
` (4 preceding siblings ...)
2010-09-05 19:00 ` [PATCH 5/8] drivers/atm/firestream.c: Fix unsigned return type Julia Lawall
@ 2010-09-05 19:00 ` Julia Lawall
2010-09-05 19:00 ` [PATCH 8/8] drivers/net/wireless/iwlwifi/iwl-agn.c: Fix return value from an unsigned function Julia Lawall
6 siblings, 0 replies; 11+ messages in thread
From: Julia Lawall @ 2010-09-05 19:00 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: kernel-janitors, devel, linux-kernel
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>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
drivers/staging/comedi/drivers/adl_pci9118.c | 2 +-
drivers/staging/comedi/drivers/ni_labpc.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c
index a2bd4e6..cb2843d 100644
--- a/drivers/staging/comedi/drivers/adl_pci9118.c
+++ b/drivers/staging/comedi/drivers/adl_pci9118.c
@@ -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)
diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c
index 3acf7e6..19f79e8 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.c
+++ b/drivers/staging/comedi/drivers/ni_labpc.c
@@ -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;
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 8/8] drivers/net/wireless/iwlwifi/iwl-agn.c: Fix return value from an unsigned function
2010-09-05 18:59 [PATCH 0/8] Fix unsigned return type Julia Lawall
` (5 preceding siblings ...)
2010-09-05 19:00 ` [PATCH 6/8] drivers/staging/comedi/drivers: " Julia Lawall
@ 2010-09-05 19:00 ` Julia Lawall
6 siblings, 0 replies; 11+ messages in thread
From: Julia Lawall @ 2010-09-05 19:00 UTC (permalink / raw)
To: Reinette Chatre
Cc: kernel-janitors, Wey-Yi Guy, Intel Linux Wireless,
John W. Linville, linux-wireless, netdev, linux-kernel
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>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
drivers/net/wireless/iwlwifi/iwl-agn.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index ad0e67f..86b55c2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -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 */
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 4/8] drivers/i2c/busses/i2c-pasemi.c: Fix unsigned
2010-09-05 19:00 ` [PATCH 4/8] drivers/i2c/busses/i2c-pasemi.c: " Julia Lawall
@ 2010-09-06 16:30 ` Olof Johansson
0 siblings, 0 replies; 11+ messages in thread
From: Olof Johansson @ 2010-09-06 16:30 UTC (permalink / raw)
To: Julia Lawall
Cc: kernel-janitors, linux-kernel, linux-i2c,
Ben Dooks (embedded platforms), Jean Delvare (PC drivers, core),
linuxppc-dev
On Sun, Sep 05, 2010 at 09:00:22PM +0200, Julia Lawall wrote:
> 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>
>
> Signed-off-by: Julia Lawall <julia@diku.dk>
Acked-by: Olof Johansson <olof@lixom.net>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/8] net/9p/trans_fd.c: Fix unsigned return type
2010-09-05 19:00 ` [PATCH 3/8] net/9p/trans_fd.c: " Julia Lawall
@ 2010-09-07 1:39 ` David Miller
0 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2010-09-07 1:39 UTC (permalink / raw)
To: julia; +Cc: kernel-janitors, netdev, linux-kernel
From: Julia Lawall <julia@diku.dk>
Date: Sun, 5 Sep 2010 21:00:21 +0200
> 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/)
...
> Signed-off-by: Julia Lawall <julia@diku.dk>
Applied.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 5/8] drivers/atm/firestream.c: Fix unsigned return type
2010-09-05 19:00 ` [PATCH 5/8] drivers/atm/firestream.c: Fix unsigned return type Julia Lawall
@ 2010-09-07 1:40 ` David Miller
0 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2010-09-07 1:40 UTC (permalink / raw)
To: julia; +Cc: chas, kernel-janitors, linux-atm-general, netdev, linux-kernel
From: Julia Lawall <julia@diku.dk>
Date: Sun, 5 Sep 2010 21:00:23 +0200
> 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/)
...
> Signed-off-by: Julia Lawall <julia@diku.dk>
Applied.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2010-09-07 1:40 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-05 18:59 [PATCH 0/8] Fix unsigned return type Julia Lawall
2010-09-05 19:00 ` [PATCH 1/8] drivers/video/matrox/matroxfb_maven.c: " Julia Lawall
2010-09-05 19:00 ` [PATCH 2/8] arch/x86/kernel/cpu/cpufreq: " Julia Lawall
2010-09-05 19:00 ` [PATCH 3/8] net/9p/trans_fd.c: " Julia Lawall
2010-09-07 1:39 ` David Miller
2010-09-05 19:00 ` [PATCH 4/8] drivers/i2c/busses/i2c-pasemi.c: " Julia Lawall
2010-09-06 16:30 ` [PATCH 4/8] drivers/i2c/busses/i2c-pasemi.c: Fix unsigned Olof Johansson
2010-09-05 19:00 ` [PATCH 5/8] drivers/atm/firestream.c: Fix unsigned return type Julia Lawall
2010-09-07 1:40 ` David Miller
2010-09-05 19:00 ` [PATCH 6/8] drivers/staging/comedi/drivers: " Julia Lawall
2010-09-05 19:00 ` [PATCH 8/8] drivers/net/wireless/iwlwifi/iwl-agn.c: Fix return value from an unsigned function Julia Lawall
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox