[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <191de70f-b019-4329-8e93-ea142aefdc7a@stanley.mountain>
Date: Wed, 2 Oct 2024 18:19:45 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: Colin Ian King <colin.i.king@...il.com>
Cc: "James E . J . Bottomley" <James.Bottomley@...senpartnership.com>,
"Martin K . Petersen" <martin.petersen@...cle.com>,
linux-scsi@...r.kernel.org, kernel-janitors@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH][next] scsi: scsi_debug: remove a redundant assignment to
variable ret
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
Powered by blists - more mailing lists