From: Dan Carpenter <dan.carpenter@linaro.org>
To: Colin Ian King <colin.i.king@gmail.com>
Cc: "James E . J . Bottomley" <James.Bottomley@hansenpartnership.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, kernel-janitors@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] scsi: scsi_debug: remove a redundant assignment to variable ret
Date: Wed, 2 Oct 2024 18:19:45 +0300 [thread overview]
Message-ID: <191de70f-b019-4329-8e93-ea142aefdc7a@stanley.mountain> (raw)
In-Reply-To: <2be706cc-0944-4413-b1b0-52d34fbdadf8@stanley.mountain>
Generally, functions which report the number of bytes copied are an anti-pattern.
bytes = copied();
if (bytes < 0)
return bytes; <-- forgot to handle partial copies
bytes = copied();
if (bytes < 0 || bytes != total)
return bytes; <-- forgot the error code for partial copies
bytes = copied();
if (bytes < sizeof()) <-- negative error codes type promoted to positive
return -EIO;
We've seen subsystems move away from this. Other subsystems are like "Ugh.
Updating all the callers is a headache. Let's either report that everything
copied or a negative error code, but not the partial bytes." Now the first
two examples above magically work.
regards,
dan carpenter
next prev parent reply other threads:[~2024-10-02 15:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-02 13:50 [PATCH][next] scsi: scsi_debug: remove a redundant assignment to variable ret Colin Ian King
2024-10-02 15:10 ` Dan Carpenter
2024-10-02 15:19 ` Dan Carpenter [this message]
2024-10-16 7:16 ` John Garry
2024-10-17 7:59 ` John Garry
2024-10-17 8:57 ` Dan Carpenter
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=191de70f-b019-4329-8e93-ea142aefdc7a@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=James.Bottomley@hansenpartnership.com \
--cc=colin.i.king@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.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