caif: Use common error handling code in cfdgml_receive()
Subsystems (3)
RFC PATCH 1/1 caif: Use common error handling code in cfdgml_receive()
From: Markus Elfring <[email protected]>
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.
---
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(-)
net/caif/cfdgml.c +17 -16
@@ -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)
Signature · 6 lines
2.15.0 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html