Discussion:
Dead code: double return
Maxime Villard
2014-08-18 09:28:13 UTC
Permalink
Hi,
my code scanner reports in several places lines like these:

return ERROR_CODE/func(XXX);
return VALUE;

Of course the latter is never reached; is there a special syntax meaning behind
this? It's ok if I fix them all? I put here [1] those which seem obvious and
harmless.

Also, I get several

panic(XX);
return;/break;/continue;

in many places; it's ok if I start removing these return;/break;/continue;?

Maxime

[1]:

Index: arch/arm/s3c2xx0/s3c24x0_lcd.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/s3c2xx0/s3c24x0_lcd.c,v
retrieving revision 1.11
diff -u -r1.11 s3c24x0_lcd.c
--- arch/arm/s3c2xx0/s3c24x0_lcd.c 10 Mar 2014 04:25:51 -0000 1.11
+++ arch/arm/s3c2xx0/s3c24x0_lcd.c 17 Aug 2014 17:05:13 -0000
@@ -735,7 +735,6 @@
offset, prot, BUS_DMA_WAITOK|BUS_DMA_COHERENT);
/* printf("s3c24x0_lcd_mmap: ret: %lx\n", ret);*/
return ret;
- return -1;
}


Index: compat/netbsd32/netbsd32_compat_50.c
===================================================================
RCS file: /cvsroot/src/sys/compat/netbsd32/netbsd32_compat_50.c,v
retrieving revision 1.24
diff -u -r1.24 netbsd32_compat_50.c
--- compat/netbsd32/netbsd32_compat_50.c 24 Jun 2014 14:33:57 -0000 1.24
+++ compat/netbsd32/netbsd32_compat_50.c 17 Aug 2014 17:05:19 -0000
@@ -139,7 +139,6 @@

return selcommon(retval, SCARG(uap, nd), SCARG_P32(uap, in),
SCARG_P32(uap, ou), SCARG_P32(uap, ex), ts, NULL);
- return 0;
}

int
@@ -563,7 +562,6 @@

return lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, tsp,
SCARG_P32(uap, hint));
- return 0;
}

static int
@@ -681,7 +679,6 @@

return selcommon(retval, SCARG(uap, nd), SCARG_P32(uap, in),
SCARG_P32(uap, ou), SCARG_P32(uap, ex), ts, mask);
- return 0;
}

int
Index: compat/netbsd32/netbsd32_compat_60.c
===================================================================
RCS file: /cvsroot/src/sys/compat/netbsd32/netbsd32_compat_60.c,v
retrieving revision 1.1
diff -u -r1.1 netbsd32_compat_60.c
--- compat/netbsd32/netbsd32_compat_60.c 29 Mar 2013 01:13:54 -0000 1.1
+++ compat/netbsd32/netbsd32_compat_60.c 17 Aug 2014 17:05:19 -0000
@@ -83,5 +83,4 @@

return lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, tsp,
SCARG_P32(uap, hint));
- return 0;
}
Index: compat/osf1/osf1_mount.c
===================================================================
RCS file: /cvsroot/src/sys/compat/osf1/osf1_mount.c,v
retrieving revision 1.50
diff -u -r1.50 osf1_mount.c
--- compat/osf1/osf1_mount.c 27 Nov 2013 17:24:44 -0000 1.50
+++ compat/osf1/osf1_mount.c 17 Aug 2014 17:05:19 -0000
@@ -314,6 +314,4 @@

return do_sys_mount(l, vfs_getopsbyname("nfs"), NULL, SCARG(uap, path),
SCARG(uap, flags), &bsd_na, UIO_SYSSPACE, sizeof bsd_na, &dummy);
-
- return 0;
}
Index: fs/ptyfs/ptyfs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/ptyfs/ptyfs_vnops.c,v
retrieving revision 1.48
diff -u -r1.48 ptyfs_vnops.c
--- fs/ptyfs/ptyfs_vnops.c 13 Aug 2014 14:10:00 -0000 1.48
+++ fs/ptyfs/ptyfs_vnops.c 17 Aug 2014 17:05:23 -0000
@@ -577,8 +577,6 @@
KAUTH_ACCESS_ACTION(ap->a_mode, ap->a_vp->v_type, va.va_mode),
ap->a_vp, NULL, genfs_can_access(va.va_type, va.va_mode, va.va_uid,
va.va_gid, ap->a_mode, ap->a_cred));
-
- return error;
}

/*
Christos Zoulas
2014-08-18 11:35:46 UTC
Permalink
Post by Maxime Villard
Hi,
return ERROR_CODE/func(XXX);
return VALUE;
Of course the latter is never reached; is there a special syntax meaning behind
this? It's ok if I fix them all? I put here [1] those which seem obvious and
harmless.
Also, I get several
panic(XX);
return;/break;/continue;
in many places; it's ok if I start removing these return;/break;/continue;?
I'd fix them. But wait for couple more people to chime in.

christos
Iain Hibbert
2014-08-18 16:01:26 UTC
Permalink
Post by Christos Zoulas
Post by Maxime Villard
Also, I get several
panic(XX);
return;/break;/continue;
in many places; it's ok if I start removing these return;/break;/continue;?
I'd fix them. But wait for couple more people to chime in.
for the non returning functions with code after, I'd say that all the
compilers currently known to be able to used with NetBSD should handle it
without complaint, since the __dead keyword is understood. However, lint
does not understand attributes..

(not saying yes or no)

regards,
iain
Christos Zoulas
2014-08-18 16:34:02 UTC
Permalink
On Aug 18, 5:01pm, ***@ogmig.net (Iain Hibbert) wrote:
-- Subject: Re: Dead code: double return

| On Mon, 18 Aug 2014, Christos Zoulas wrote:
|
| > In article <***@M00nBSD.net>,
| > Maxime Villard <***@M00nBSD.net> wrote:
| > >Also, I get several
| > >
| > > panic(XX);
| > > return;/break;/continue;
| > >
| > >in many places; it's ok if I start removing these return;/break;/continue;?
| >
| > I'd fix them. But wait for couple more people to chime in.
|
| for the non returning functions with code after, I'd say that all the
| compilers currently known to be able to used with NetBSD should handle it
| without complaint, since the __dead keyword is understood. However, lint
| does not understand attributes..

Lint does now have code for parsing attributes and some are even implemented.
Compilers should warn about dead code, after dead functions but some don't :-)

christos
David Young
2014-08-18 17:03:02 UTC
Permalink
Post by Maxime Villard
Hi,
return ERROR_CODE/func(XXX);
return VALUE;
In some of your examples, it looks like code may have been copied and
pasted. Is some refactoring of the code called for?

Dave
--
David Young
***@pobox.com Urbana, IL (217) 721-9981
matthew green
2014-08-18 18:50:40 UTC
Permalink
Post by David Young
Post by Maxime Villard
Hi,
return ERROR_CODE/func(XXX);
return VALUE;
In some of your examples, it looks like code may have been copied and
pasted. Is some refactoring of the code called for?
hopefully not for code and bug fixes destined for netbsd-7.


.mrg.

Loading...