Skip to content

Commit da78b79

Browse files
JuliaLawallmarckleinebudde
authored andcommitted
can: softing: softing_main: ensure a consistent return value in error case
Typically, the return value desired for the failure of a function with an integer return value is a negative integer. In these cases, the return value is sometimes a negative integer and sometimes 0, due to a subsequent initialization of the return variable within the loop. A simplified version of the semantic match that finds this problem is: (http://coccinelle.lip6.fr/) //<smpl> @r exists@ identifier ret; position p; constant C; expression e1,e3,e4; statement S; @@ ret = -C ... when != ret = e3 when any if@p (...) S ... when any if (\(ret != 0\|ret < 0\|ret > 0\) || ...) { ... return ...; } ... when != ret = e3 when any *if@p (...) { ... when != ret = e4 return ret; } //</smpl> Signed-off-by: Julia Lawall <[email protected]> Acked-by: Kurt Van Dijck <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 0e84eb0 commit da78b79

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/net/can/softing/softing_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,12 +826,12 @@ static __devinit int softing_pdev_probe(struct platform_device *pdev)
826826
goto sysfs_failed;
827827
}
828828

829-
ret = -ENOMEM;
830829
for (j = 0; j < ARRAY_SIZE(card->net); ++j) {
831830
card->net[j] = netdev =
832831
softing_netdev_create(card, card->id.chip[j]);
833832
if (!netdev) {
834833
dev_alert(&pdev->dev, "failed to make can[%i]", j);
834+
ret = -ENOMEM;
835835
goto netdev_failed;
836836
}
837837
priv = netdev_priv(card->net[j]);

0 commit comments

Comments
 (0)