All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tony Battersby <tonyb@cybernetics.com>
To: dgilbert@interlog.com, linux-scsi@vger.kernel.org,
	"James E.J. Bottomley" <JBottomley@parallels.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] [SCSI] sg: fix read() error reporting
Date: Wed, 11 Feb 2015 13:13:43 -0500	[thread overview]
Message-ID: <54DB9BD7.7090605@cybernetics.com> (raw)
In-Reply-To: <54DB953C.1090104@interlog.com>

On 02/11/2015 12:45 PM, Douglas Gilbert wrote:
> 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
>
>
>
I checked before submitting, and the foo ? : bar construct is already
used at least 455 times in the kernel, so it is nothing new.

find linux-3.19 -type f -name "*.[ch]" | xargs grep '\? :' | wc -l
455

But you are probably right; I think that with such small variable names
your version is more readable due to the nesting.  Updated patch below.

---

Fix SCSI generic read() incorrectly returning success after detecting an
error.

Cc: <stable@vger.kernel.org>
Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
---

--- 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-11 13:02:56.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 ? err : (err2 ? err2 : count);
 }
 
 static ssize_t

  reply	other threads:[~2015-02-11 18:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-11 16:32 [PATCH] [SCSI] sg: fix read() error reporting Tony Battersby
2015-02-11 17:45 ` Douglas Gilbert
2015-02-11 18:13   ` Tony Battersby [this message]
2015-02-12 23:31     ` Douglas Gilbert

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=54DB9BD7.7090605@cybernetics.com \
    --to=tonyb@cybernetics.com \
    --cc=JBottomley@parallels.com \
    --cc=dgilbert@interlog.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.