From: SF Markus Elfring <elfring@users.sourceforge.net>
To: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>,
Sjur Braendeland <sjur.brandeland@stericsson.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH RFC v1] caif: Use common error handling code in cfdgml_receive()
Date: Tue, 7 Nov 2017 16:02:32 +0100 [thread overview]
Message-ID: <034c0760-b8af-0fe2-e7a0-81199ff31931@users.sourceforge.net> (raw)
From: Markus Elfring <elfring@users.sourceforge.net>
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@users.sourceforge.net>
---
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
reply other threads:[~2017-11-07 15:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=034c0760-b8af-0fe2-e7a0-81199ff31931@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=davem@davemloft.net \
--cc=dmitry.tarnyagin@lockless.no \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sjur.brandeland@stericsson.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).