From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx> Date: Tue, 7 Nov 2017 11:30:25 +0100 * Adjust jump targets so that a bit of exception handling can be better reused at the end of this function. * Adjust two condition checks. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx> --- v1 - Request for comments: I can offer another bit of information for a software development discussion. 💭 The affected source file can be compiled for the processor architecture “x86_64” by a tool like “GCC 6.4.1+r251631-1.3” from the software distribution “openSUSE Tumbleweed” with the following command example. my_cc=/usr/bin/gcc-6 \ && my_module=net/caif/cfdgml.o \ && for XYZ in 0 s 3; do echo " _____ $XYZ _____" \ && my_extra="-O$XYZ" \ && git checkout next-20171102 \ && make -j4 CC="${my_cc}" HOSTCC="${my_cc}" EXTRA_CFLAGS="${my_extra}" allmodconfig "${my_module}" \ && size "${my_module}" \ && git checkout ':/^caif: Use common error handling code in cfdgml_receive' \ && make -j4 CC="${my_cc}" HOSTCC="${my_cc}" EXTRA_CFLAGS="${my_extra}" allmodconfig "${my_module}" \ && size "${my_module}"; done 🔮 Do you find the following differences worth for further clarification? ╔═════════╤══════╗ ║ setting │ text ║ ╠═════════╪══════╣ ║ O0 │ -59 ║ ║ Os │ +24 ║ ║ O3 │ +36 ║ ╚═════════╧══════╝ net/caif/cfdgml.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/net/caif/cfdgml.c b/net/caif/cfdgml.c index 3bdddb32d55a..cc7b2c944bb2 100644 --- a/net/caif/cfdgml.c +++ b/net/caif/cfdgml.c @@ -47,18 +47,13 @@ static int cfdgml_receive(struct cflayer *layr, struct cfpkt *pkt) caif_assert(layr->receive != NULL); caif_assert(layr->ctrlcmd != NULL); - if (cfpkt_extr_head(pkt, &cmd, 1) < 0) { - pr_err("Packet is erroneous!\n"); - cfpkt_destroy(pkt); - return -EPROTO; - } + if (cfpkt_extr_head(pkt, &cmd, 1)) + goto report_packet_failure; if ((cmd & DGM_CMD_BIT) == 0) { - if (cfpkt_extr_head(pkt, &dgmhdr, 3) < 0) { - pr_err("Packet is erroneous!\n"); - cfpkt_destroy(pkt); - return -EPROTO; - } + if (cfpkt_extr_head(pkt, &dgmhdr, 3)) + goto report_packet_failure; + ret = layr->up->receive(layr->up, pkt); return ret; } @@ -66,17 +61,23 @@ static int cfdgml_receive(struct cflayer *layr, struct cfpkt *pkt) switch (cmd) { case DGM_FLOW_OFF: /* FLOW OFF */ layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_OFF_IND, 0); - cfpkt_destroy(pkt); - return 0; + ret = 0; + goto destroy_packet; case DGM_FLOW_ON: /* FLOW ON */ layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_ON_IND, 0); - cfpkt_destroy(pkt); - return 0; + ret = 0; + goto destroy_packet; default: - cfpkt_destroy(pkt); pr_info("Unknown datagram control %d (0x%x)\n", cmd, cmd); - return -EPROTO; + goto e_proto; } +report_packet_failure: + pr_err("Packet is erroneous!\n"); +e_proto: + ret = -EPROTO; +destroy_packet: + cfpkt_destroy(pkt); + return ret; } static int cfdgml_transmit(struct cflayer *layr, struct cfpkt *pkt) -- 2.15.0 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html