From: Pete Zaitcev <zaitcev@redhat.com>
To: Salah Triki <salah.triki@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
zaitcev@redhat.com
Subject: Re: [PATCH] usb: class: usblp: replace conditional statement with min()
Date: Mon, 2 Aug 2021 20:50:22 -0500 [thread overview]
Message-ID: <20210802205022.357279fc@suzdal.zaitcev.lan> (raw)
In-Reply-To: <20210803002806.GA1541734@pc>
On Tue, 3 Aug 2021 01:28:06 +0100
Salah Triki <salah.triki@gmail.com> wrote:
> Replace conditional statement with min() in order to make code cleaner. Issue
> found by coccinelle.
> +++ b/drivers/usb/class/usblp.c
> request, !!dir, recip, value, index, len, retval);
> - return retval < 0 ? retval : 0;
> + return min(retval, 0);
> }
I'm very much against this change. The function min() is there
for numeric values. But here we have a situation where we
do one thing if there was an error, and another thing if
there was no error.
This sort of abuse is exactly why blindly clicking heels
whenever a tool tells you is not optimal.
If the objective is to shut the tool up, please consider
the following instead:
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 9596e4279294..bbcbcf199fa9 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -264,7 +264,9 @@ static int usblp_ctrl_msg(struct usblp *usblp, int request, int type, int dir, i
dev_dbg(&usblp->intf->dev,
"usblp_control_msg: rq: 0x%02x dir: %d recip: %d value: %d idx: %d len: %#x result: %d\n",
request, !!dir, recip, value, index, len, retval);
- return retval < 0 ? retval : 0;
+ if (retval < 0)
+ return retval;
+ return 0;
}
#define usblp_read_status(usblp, status)\
-- Pete
next prev parent reply other threads:[~2021-08-03 1:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-03 0:28 [PATCH] usb: class: usblp: replace conditional statement with min() Salah Triki
2021-08-03 1:50 ` Pete Zaitcev [this message]
2021-08-03 5:13 ` Greg Kroah-Hartman
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=20210802205022.357279fc@suzdal.zaitcev.lan \
--to=zaitcev@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=salah.triki@gmail.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