lkml.org 
[lkml]   [2015]   [Feb]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] [SCSI] sg: fix read() error reporting
On 15-02-11 11:32 AM, Tony Battersby wrote:
> Fix SCSI generic read() incorrectly returning success after detecting an
> error.
>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
> ---
>
> For inclusion in kernel 3.20.
>
> --- linux-3.19.0/drivers/scsi/sg.c.orig 2015-02-08 21:54:22.000000000 -0500
> +++ linux-3.19.0/drivers/scsi/sg.c 2015-02-10 09:26:09.000000000 -0500
> @@ -546,7 +546,7 @@ static ssize_t
> sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp)
> {
> sg_io_hdr_t *hp = &srp->header;
> - int err = 0;
> + int err = 0, err2;
> int len;
>
> if (count < SZ_SG_IO_HDR) {
> @@ -575,8 +575,8 @@ sg_new_read(Sg_fd * sfp, char __user *bu
> goto err_out;
> }
> err_out:
> - err = sg_finish_rem_req(srp);
> - return (0 == err) ? count : err;
> + err2 = sg_finish_rem_req(srp);
> + return err ? : err2 ? : count;

Tony,
Your point is well made.

I just don't like that last line, using a gcc extension that
hasn't even made it into C11 (or C++11). Wouldn't:
return err ? err : (err2 ? err2 : count);

be a bit better? I think the following snippet makes the intent
clear but would it generate any more code:
if (err || err2)
return err ? err : err2;
else
return count;

Doug Gilbert




\
 
 \ /
  Last update: 2015-02-11 19:01    [W:0.118 / U:0.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site