2.4.21-pre4 comparison bugs
Subsystems (16)
Hello!
Thanks to whoever mentioned "gcc -W", it's *sweet* ;) Looking at it's output I found few cases where error checking does not work.
Though nothing too serious it seems (except maybe IDE setup-pci stuff, I just do not know about that, and may be in that case
we actually want to change all the functions to return signed value, though my fix is certainly less intrusive ;) )
Most of the patched stuff in here assigns signed value to unsigned variable and then checks if it is less than zero which does not work for obvious reasons ;)
I decided taht in most cases simple casting to int would be best and least intrusive resolution of a problem.
The only exception is fs/isofs/inode.c, there we have unsigned int (so it is unsigned not depending on any arch) and so '> some num' stuff will also check for former negative numbers anyway. So I removed one extra comparison in that case.
See the patch below.
Bye,
Oleg
===== drivers/ide/setup-pci.c 1.2 vs edited =====
drivers/ide/setup-pci.c +2 -2
@@ -582,7 +582,7 @@ index.all =0xf0f0 ; -if ((autodma =ide_setup_pci_controller (dev, d, noisy, &tried_config)) <0 ) +if ((int )(autodma =ide_setup_pci_controller (dev, d, noisy, &tried_config)) <0 )return index;/*
@@ -613,7 +613,7 @@ }else {if (d->init_chipset) { -if (d->init_chipset (dev, d->name) <0 ) +if ((int )d->init_chipset (dev, d->name) <0 )return index; }if (noisy)
===== drivers/net/tun.c 1.8 vs edited =====
drivers/net/tun.c +1 -1
@@ -188,7 +188,7 @@size_t len = count;if (!(tun->flags &TUN_NO_PI )) { -if ((len -=sizeof (pi)) <0 ) +if ((int )(len -=sizeof (pi)) <0 )return -EINVAL ;memcpy_fromiovec ((void *)&pi, iv,sizeof (pi));
===== fs/isofs/inode.c 1.9 vs edited =====
fs/isofs/inode.c +2 -2
@@ -343,13 +343,13 @@if (!strcmp (this_char,"session" ) && value) {char * vpnt = value;unsigned int ivalue =simple_strtoul (vpnt, &vpnt,0 ); -if (ivalue <0 || ivalue >99 )return 0 ; +if (ivalue >99 )return 0 ; popt->session=ivalue+1 ; }if (!strcmp (this_char,"sbsector" ) && value) {char * vpnt = value;unsigned int ivalue =simple_strtoul (vpnt, &vpnt,0 ); -if (ivalue <0 || ivalue >660 *512 )return 0 ; +if (ivalue >660 *512 )return 0 ; popt->sbsector=ivalue; }else if (!strcmp (this_char,"check" ) && value) {
===== net/sunrpc/pmap_clnt.c 1.3 vs edited =====
net/sunrpc/pmap_clnt.c +1 -1
@@ -149,7 +149,7 @@struct sockaddr_in sin;struct rpc_portmap map;struct rpc_clnt *pmap_clnt; -unsigned int error =0 ; +int error =0 ;dprintk ("RPC: registering (%d, %d, %d, %d) with portmapper.\n" , prog, vers, prot, port);
Quoted 11 lines · On 2003.02.08 Oleg Drokin wrote:
Hello!
Thanks to whoever mentioned "gcc -W", it's *sweet* ;) Looking at it's output I found few cases where error checking does not work.
Though nothing too serious it seems (except maybe IDE setup-pci stuff, I just do not know about that, and may be in that case
we actually want to change all the functions to return signed value, though my fix is certainly less intrusive ;) )
Most of the patched stuff in here assigns signed value to unsigned variable and then checks if it is less than zero which does not work
Quoted 9 lines
for obvious reasons ;)
I decided taht in most cases simple casting to int would be best and least intrusive resolution of a problem.
The only exception isfs/isofs/inode.c, there we have unsigned int (so it is unsigned not depending on any arch) and so '> some num' stuff will also check for former negative numbers anyway. So I removed one extra comparison in that case.
See the patch below.
So:
unsgined f()
{
return -1;
}if ((int)f()<0)
??
Wouldn't you get killed by some kind of bit/sign extension in the return ? Just to be sure, probably the answer is just 'go learn C internals'...
Signature · 4 lines
J.A. Magallon <[email protected]> \ Software is like sex: werewolf.able.es \ It's better when it's free Mandrake Linux release 9.1 (Cooker) for i586 Linux 2.4.21-pre4-jam1 (gcc 3.2.1 (Mandrake Linux 9.1 3.2.1-5mdk))
Quoted 7 lines · J.A. Magallon
So:
unsgined
f(){ return -1; }
Quoted 5 lines
if ((int)f()<0)
??Wouldn't you get killed by some kind of bit/sign extension in the return ? Just to be sure, probably the answer is just 'go learn C internals'...
Fuzzy thinking and non-portable. I think the answer is that someone didn't put enough thought into the error returns. This is trickery to avoid defining an error value to return. One of those "it works on most compilers and computers" things. Definitely low human readability. If the return value is always small enough to be positive if cast to (int), why not return int? Can't say without looking at actual code rather than a general example.
Because it mostly works, I'm not sure what priority a more readable return code would have, though.
Signature · 3 lines
bill davidsen <[email protected]> CTO, TMR Associates, Inc Doing interesting things with little computers since 1979.
drivers/ide/setup-pci.c line 586
Quoted 3 lines · Oleg Drokin
drivers/ide/setup-pci.c +1
-1-if ((autodma =ide_setup_pci_controller (dev, d, noisy, &tried_config)) <0 ) +if ((int )(autodma =ide_setup_pci_controller (dev, d, noisy, &tried_config)) <0 )return index;
Well caught. I don't like your fix. I'd prefer to do the job properly and either make it return a signed value or split error/value reporting in these various cases.
I'll fix them for the next -ac
Re: 2.4.21-pre4 comparison bugs (More of those)
Hello!
Quoted 7 lines · Alan Cox
Review
Quoted 3 lines
(quoted diff) +1
-1- if((autodma = ide_setup_pci_controller(dev, d, noisy, &tried_config)) < 0) + if((int)(autodma = ide_setup_pci_controller(dev, d, noisy, &tried_config)) < 0) return index;Well caught. I don't like your fix. I'd prefer to do the job properly and either make it return a signed value or split error/value reporting in these various cases.
I'll fix them for the next -ac
Ok, here is some more for you ;)
This time I changed the type of variable to signed type whenever I felt it was appropriate.
When I was not sure (or unsigned type was in some commonly used structure), I still used a cast just to highlight a problem, so that someone more knowledgeable created better fix.
See the patch.
Mostly we do incorrect stuff on errors. Sigh, nobody likes errors ;)
Bye,
Oleg
===== drivers/char/mwave/mwavedd.c 1.3 vs edited =====
drivers/char/mwave/mwavedd.c +1 -1
@@ -500,7 +500,7 @@ {int i;int retval =0 ; -unsigned int resultMiscRegister; +int resultMiscRegister;pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd;memset (&mwave_s_mdd,0 ,sizeof (MWAVE_DEVICE_DATA ));
===== drivers/isdn/hisax/st5481_usb.c 1.8 vs edited =====
drivers/isdn/hisax/st5481_usb.c +1 -1
@@ -576,7 +576,7 @@ pipd < pend; pipd++) { -if (pipd->status <0 ) { +if ((int )pipd->status <0 ) {return (pipd->status); }
===== drivers/message/fusion/mptbase.c 1.7 vs edited =====
drivers/message/fusion/mptbase.c +1 -1
@@ -1801,7 +1801,7 @@ {if (this !=NULL ) {int sz; -u32 state; +int state;/* Disable the FW */ state =mpt_GetIocState (this,1 );
===== drivers/mtd/devices/slram.c 1.6 vs edited =====
drivers/mtd/devices/slram.c +2 -2
@@ -246,8 +246,8 @@int parse_cmdline (char *devname,char *szstart,char *szlength) {char *buffer; -unsigned long devstart; -unsigned long devlength; +long devstart; +long devlength;if ((!devname) || (!szstart) || (!szlength)) {unregister_devices ();
===== drivers/net/acenic.c 1.27 vs edited =====
drivers/net/acenic.c +2 -2
@@ -1157,8 +1157,8 @@struct pci_dev *pdev;unsigned long myjif;u64 tmp_ptr; -u32 tig_ver, mac1, mac2, tmp, pci_state; -int board_idx, ecode =0 ; +u32 tig_ver, mac1, mac2, pci_state; +int board_idx, ecode =0 , tmp;short i;unsigned char cache_size;
===== drivers/net/wan/8253x/8253xini.c 1.1 vs edited =====
drivers/net/wan/8253x/8253xini.c +1 -1
@@ -2196,7 +2196,7 @@SAB_BOARD *boardptr;SAB_PORT *portptr;struct net_device *dev; -unsigned int result; +int result;unsigned int namelength;unsigned int portno;int intr_val;
===== drivers/net/wan/8253x/8253xtty.c 1.1 vs edited =====
drivers/net/wan/8253x/8253xtty.c +1 -1
@@ -135,7 +135,7 @@ registerunsigned int slopspace; registerint sendsize;unsigned int totaltransmit; -unsigned fifospace; +int fifospace;unsigned loadedcount;struct tty_struct *tty = port->tty;
===== drivers/scsi/osst.c 1.10 vs edited =====
drivers/scsi/osst.c +1 -1
@@ -4680,7 +4680,7 @@ unsigned int cmd_in, unsigned long arg) { int i, cmd_nr, cmd_type, retval = 0; -unsigned int blk; +int blk;OS_Scsi_Tape *STp;ST_mode *STm;ST_partstat *STps;
===== drivers/scsi/aacraid/aachba.c 1.3 vs edited =====
drivers/scsi/aacraid/aachba.c +2 -1
@@ -233,7 +233,8 @@int aac_get_containers (struct aac_dev *dev) {struct fsa_scsi_hba *fsa_dev_ptr; -u32 index, status =0 ; +u32 index; +int status =0 ;struct aac_query_mount *dinfo;struct aac_mount *dresp;struct fib * fibptr;
===== drivers/usb/hcd/ehci-sched.c 1.7 vs edited =====
drivers/usb/hcd/ehci-sched.c +1 -1
@@ -549,7 +549,7 @@u64 temp;u32 buf1;unsigned i, epnum, maxp, multi; -unsigned length; +int length;int is_input; itd->hw_next =EHCI_LIST_END ;
===== fs/intermezzo/psdev.c 1.7 vs edited =====
fs/intermezzo/psdev.c +1 -1
@@ -605,7 +605,7 @@if (req->rq_flags &REQ_WRITE ) { out = (struct izo_upcall_resp *)req->rq_data;/* here we map positive Lento errors to kernel errors */ -if ( out->result <0 ) { +if ( (int )out->result <0 ) {CERROR ("Tell Peter: Lento returns negative error %d, for oc %d!\n" , out->result, out->opcode); out->result =EINVAL ;
===== fs/intermezzo/super.c 1.4 vs edited =====
fs/intermezzo/super.c +1 -1
@@ -200,7 +200,7 @@char *fileset =NULL ;char *channel =NULL ;int err; -unsigned int minor; +int minor;ENTRY ;
===== net/decnet/af_decnet.c 1.12 vs edited =====
net/decnet/af_decnet.c +1 -1
@@ -1180,7 +1180,7 @@struct sock *sk = sock->sk;struct dn_scp *scp =DN_SK (sk);int err = -EOPNOTSUPP ; -unsigned long amount =0 ; +long amount =0 ;struct sk_buff *skb;int val;
===== net/ipv4/netfilter/ip_conntrack_irc.c 1.5 vs edited =====
net/ipv4/netfilter/ip_conntrack_irc.c +1 -1
@@ -37,7 +37,7 @@static int ports[MAX_PORTS ];static int ports_c =0 ;static int max_dcc_channels =8 ; -static unsigned int dcc_timeout =300 ; +static int dcc_timeout =300 ;MODULE_AUTHOR ("Harald Welte <[email protected]>" );MODULE_DESCRIPTION ("IRC (DCC) connection tracking module" );
Re: 2.4.21-pre4 comparison bugs (Even More Again)
Hello!
Ok. In addition to "unsigned_var < 0" kind of error checks that never work, there is different non-working kind of checks:
"pointer < 0".
We can see these at:drivers/char/joystick/tmdc.c:318 if (tmdc->abs[i] < 0) continue;drivers/char/epca.c:3758 if (board.port <= 0)drivers/char/epca.c:3770 if (board.membase <= 0)drivers/media/radio/radio-cadet.c:541 if(request_region(io,2, "cadet-probe")>=0) {drivers/net/wan/dscc4.c:1760 if (dscc4_init_dummy_skb(dpriv) < 0)
Given the fact that you seem not to like casts to signed int, how do you propose to fix these?
Bye,
Oleg
Re: 2.4.21-pre4 comparison bugs (Even More Again)
Quoted 12 lines · Oleg Drokin
Hello!
Ok. In addition to "
unsigned_var< 0" kind of error checks that never work, there is different non-working kind of checks:
"pointer < 0".
We can see these at:drivers/char/joystick/tmdc.c:318if (tmdc->abs[i] < 0) continue;drivers/char/epca.c:3758if (board.port <= 0)drivers/char/epca.c:3770if (board.membase <= 0)drivers/media/radio/radio-cadet.c:541if(request_region(io,2, "cadet-probe")>=0){drivers/net/wan/dscc4.c:1760if (dscc4_init_dummy_skb(dpriv)< 0)
Quoted 2 lines
Given the fact that you seem not to like casts to signed int, how do you propose to fix these?
By actually going and reading the drivers to see why the errors occur and if they are meaningful. You need to know the possible returns and the intent of those returns.
Eg radio-cadet request region appears not be a cast problem but a complete misunderstanding of the return codes. Likewise epca it looks like the board.port/board.membase are just overbroad checks and in fact harmless.
Re: 2.4.21-pre4 comparison bugs (More of those)
In reply to Oleg DrokinQuoted 7 lines · Oleg Drokin
This time I changed the type of variable to signed type whenever I felt it was appropriate.
When I was not sure (or unsigned type was in some commonly used structure), I still used a cast just to highlight a problem, so that someone more knowledgeable created better fix.
See the patch.
Mostly we do incorrect stuff on errors. Sigh, nobody likes errors ;)
Hiding them is even worse than having them there visible and unfixed. Changing the sign on stuff holding physical addresses is actually introducing real bugs
Re: 2.4.21-pre4 comparison bugs (More of those)
Hello!
Quoted 10 lines · Alan Cox
Quoted 7 lines
This time I changed the type of variable to signed type whenever I felt it was appropriate.
When I was not sure (or unsigned type was in some commonly used structure), I still used a cast just to highlight a problem, so that someone more knowledgeable created better fix.
See the patch.
Mostly we do incorrect stuff on errors. Sigh, nobody likes errors ;)Hiding them is even worse than having them there visible and unfixed. Changing the sign on stuff holding physical addresses is actually introducing real bugs
I assume you are speaking of slram stuff here.
I thought that slram was not designed to work with parts of RAM past 2G border. (as far as I remember, slram was used on old x86 HW to convert uncached RAM beyond 64M (256M for some systems?) into kind of a ramdisk.)
Bye,
Oleg
2.4.21-pre4 more extra semicolons bugs
In reply to Oleg DrokinHello!
It is a boring sunday here today, so I decided to play with gcc -W on a 2.4.21-pre4 (from current bitkeeper tree) with all the stuff possible compiled in.
Seems that megaraid and 8253xtty have extra semicolons. Nothing too serious, though.
Bye,
Oleg
===== drivers/net/wan/8253x/8253xtty.c 1.1 vs edited =====
drivers/net/wan/8253x/8253xtty.c +1 -1
@@ -2131,7 +2131,7 @@/* Check whether or not the port is open in SYNC mode */ if (port->open_type ==OPEN_SYNC_NET ) { -if (port->dev &&netif_carrier_ok (port->dev)); +if (port->dev &&netif_carrier_ok (port->dev)) { port->tty=NULL ;/* Don't bother with open counting here but make sure the tty field is NULL*/
===== drivers/scsi/megaraid.c 1.21 vs edited =====
drivers/scsi/megaraid.c +1 -1
@@ -4936,7 +4936,7 @@if ( ioc.mbox[0 ] ==MEGA_MBOXCMD_PASSTHRU ) {put_user ( scsicmd->result, &uioc->pthru.scsistatus );if (copy_to_user ( uioc->pthru.reqsensearea, scsicmd->sense_buffer, -MAX_REQ_SENSE_LEN )); +MAX_REQ_SENSE_LEN )) ret= -EFAULT ; }else {put_user (1 , &uioc->mbox[16 ]);/* numstatus */
2.4.21-pre4 - two simple compile fixes
Hello!
With this trivial patch below I am able to compile with support for come Cadet radio card and NatSemi SCx200
Bye,
Oleg
===== drivers/char/Makefile 1.30 vs edited =====
drivers/char/Makefile +1 -1
@@ -24,7 +24,7 @@ export-objs := busmouse.o console.o keyboard.o sysrq.o \ misc.o pty.o random.o selection.o serial.o \ sonypi.o tty_io.o tty_ioctl.o generic_serial.o \ - au1000_gpio.o hp_psaux.o nvram.o + au1000_gpio.o hp_psaux.o nvram.o scx200.o mod-subdirs := joystick ftape drm drm-4.0 pcmcia
===== drivers/media/radio/radio-cadet.c 1.5 vs edited =====
drivers/media/radio/radio-cadet.c +1 -1
@@ -558,7 +558,7 @@static int __init cadet_init (void ) { -spin_lock_init (&cadet_lock); +spin_lock_init (&cadet_io_lock);/* * If a probe was requested then probe ISAPnP first (safest)
Re: 2.4.21-pre4 - two simple compile fixes
Quoted 5 lines · Oleg Drokin
Hello!
With this trivial patch below I am able to compile with support for come Cadet radio card and NatSemi SCx200
I sent Marcelo the cadet one already and its fine, the scx200 one looks right too I'll check that in -ac