* [Qemu-devel] [PATCH] 9pfs-proxy: tiny cleanups in proxy_pwritev and proxy_preadv
@ 2015-03-10 5:54 Michael Tokarev
2015-03-10 7:15 ` Gonglei
2015-03-10 17:23 ` Aneesh Kumar K.V
0 siblings, 2 replies; 6+ messages in thread
From: Michael Tokarev @ 2015-03-10 5:54 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Michael Tokarev, Aneesh Kumar K.V
Don't compare syscall return with -1, use "<0" condition.
Don't introduce useless local variables when we already
have similar variable
Rename local variable to be consistent with other usages
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
hw/9pfs/virtio-9p-proxy.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
index 59c7445..a01804a 100644
--- a/hw/9pfs/virtio-9p-proxy.c
+++ b/hw/9pfs/virtio-9p-proxy.c
@@ -696,9 +696,9 @@ static ssize_t proxy_preadv(FsContext *ctx, V9fsFidOpenState *fs,
#ifdef CONFIG_PREADV
return preadv(fs->fd, iov, iovcnt, offset);
#else
- int err = lseek(fs->fd, offset, SEEK_SET);
- if (err == -1) {
- return err;
+ int ret = lseek(fs->fd, offset, SEEK_SET);
+ if (err < 0)
+ return ret;
} else {
return readv(fs->fd, iov, iovcnt);
}
@@ -714,10 +714,8 @@ static ssize_t proxy_pwritev(FsContext *ctx, V9fsFidOpenState *fs,
#ifdef CONFIG_PREADV
ret = pwritev(fs->fd, iov, iovcnt, offset);
#else
- int err = lseek(fs->fd, offset, SEEK_SET);
- if (err == -1) {
- return err;
- } else {
+ ret = lseek(fs->fd, offset, SEEK_SET);
+ if (ret >= 0) {
ret = writev(fs->fd, iov, iovcnt);
}
#endif
--
2.1.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] 9pfs-proxy: tiny cleanups in proxy_pwritev and proxy_preadv
2015-03-10 5:54 [Qemu-devel] [PATCH] 9pfs-proxy: tiny cleanups in proxy_pwritev and proxy_preadv Michael Tokarev
@ 2015-03-10 7:15 ` Gonglei
2015-03-10 7:20 ` Michael Tokarev
2015-03-10 17:23 ` Aneesh Kumar K.V
1 sibling, 1 reply; 6+ messages in thread
From: Gonglei @ 2015-03-10 7:15 UTC (permalink / raw)
To: Michael Tokarev, qemu-devel; +Cc: qemu-trivial, Aneesh Kumar K.V
On 2015/3/10 13:54, Michael Tokarev wrote:
> Don't compare syscall return with -1, use "<0" condition.
> Don't introduce useless local variables when we already
> have similar variable
> Rename local variable to be consistent with other usages
>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> hw/9pfs/virtio-9p-proxy.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
> index 59c7445..a01804a 100644
> --- a/hw/9pfs/virtio-9p-proxy.c
> +++ b/hw/9pfs/virtio-9p-proxy.c
> @@ -696,9 +696,9 @@ static ssize_t proxy_preadv(FsContext *ctx, V9fsFidOpenState *fs,
> #ifdef CONFIG_PREADV
> return preadv(fs->fd, iov, iovcnt, offset);
> #else
> - int err = lseek(fs->fd, offset, SEEK_SET);
> - if (err == -1) {
> - return err;
> + int ret = lseek(fs->fd, offset, SEEK_SET);
> + if (err < 0)
> + return ret;
The above code fragment is confused.
Regards,
-Gonglei
> } else {
> return readv(fs->fd, iov, iovcnt);
> }
> @@ -714,10 +714,8 @@ static ssize_t proxy_pwritev(FsContext *ctx, V9fsFidOpenState *fs,
> #ifdef CONFIG_PREADV
> ret = pwritev(fs->fd, iov, iovcnt, offset);
> #else
> - int err = lseek(fs->fd, offset, SEEK_SET);
> - if (err == -1) {
> - return err;
> - } else {
> + ret = lseek(fs->fd, offset, SEEK_SET);
> + if (ret >= 0) {
> ret = writev(fs->fd, iov, iovcnt);
> }
> #endif
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] 9pfs-proxy: tiny cleanups in proxy_pwritev and proxy_preadv
2015-03-10 7:15 ` Gonglei
@ 2015-03-10 7:20 ` Michael Tokarev
2015-03-10 7:27 ` Gonglei
0 siblings, 1 reply; 6+ messages in thread
From: Michael Tokarev @ 2015-03-10 7:20 UTC (permalink / raw)
To: Gonglei, qemu-devel; +Cc: qemu-trivial, Aneesh Kumar K.V
10.03.2015 10:15, Gonglei wrote:
> On 2015/3/10 13:54, Michael Tokarev wrote:
>> Don't compare syscall return with -1, use "<0" condition.
>> Don't introduce useless local variables when we already
>> have similar variable
>> Rename local variable to be consistent with other usages
>>
>> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
>> ---
>> hw/9pfs/virtio-9p-proxy.c | 12 +++++-------
>> 1 file changed, 5 insertions(+), 7 deletions(-)
>>
>> diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
>> index 59c7445..a01804a 100644
>> --- a/hw/9pfs/virtio-9p-proxy.c
>> +++ b/hw/9pfs/virtio-9p-proxy.c
>> @@ -696,9 +696,9 @@ static ssize_t proxy_preadv(FsContext *ctx, V9fsFidOpenState *fs,
>> #ifdef CONFIG_PREADV
>> return preadv(fs->fd, iov, iovcnt, offset);
>> #else
>> - int err = lseek(fs->fd, offset, SEEK_SET);
>> - if (err == -1) {
>> - return err;
>> + int ret = lseek(fs->fd, offset, SEEK_SET);
>> + if (err < 0)
>> + return ret;
>
> The above code fragment is confused.
Sorry I don't understand, can you elaborate please?
Note I haven't changed much in there, just variable
rename and changed the condition within if: s/== -1/< 0/.
(BTW, a code fragment can't be confused, it might be
confusing I think, with a reader being confused.
A confused code is um.. something -- a code who doesn't
know what to do... ;) Sorry can't resist ;)
Thanks,
/mjt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] 9pfs-proxy: tiny cleanups in proxy_pwritev and proxy_preadv
2015-03-10 7:20 ` Michael Tokarev
@ 2015-03-10 7:27 ` Gonglei
0 siblings, 0 replies; 6+ messages in thread
From: Gonglei @ 2015-03-10 7:27 UTC (permalink / raw)
To: Michael Tokarev, qemu-devel; +Cc: qemu-trivial, Aneesh Kumar K.V
On 2015/3/10 15:20, Michael Tokarev wrote:
> 10.03.2015 10:15, Gonglei wrote:
>> On 2015/3/10 13:54, Michael Tokarev wrote:
>>> Don't compare syscall return with -1, use "<0" condition.
>>> Don't introduce useless local variables when we already
>>> have similar variable
>>> Rename local variable to be consistent with other usages
>>>
>>> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
>>> ---
>>> hw/9pfs/virtio-9p-proxy.c | 12 +++++-------
>>> 1 file changed, 5 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
>>> index 59c7445..a01804a 100644
>>> --- a/hw/9pfs/virtio-9p-proxy.c
>>> +++ b/hw/9pfs/virtio-9p-proxy.c
>>> @@ -696,9 +696,9 @@ static ssize_t proxy_preadv(FsContext *ctx, V9fsFidOpenState *fs,
>>> #ifdef CONFIG_PREADV
>>> return preadv(fs->fd, iov, iovcnt, offset);
>>> #else
>>> - int err = lseek(fs->fd, offset, SEEK_SET);
>>> - if (err == -1) {
>>> - return err;
>>> + int ret = lseek(fs->fd, offset, SEEK_SET);
>>> + if (err < 0)
>>> + return ret;
>>
>> The above code fragment is confused.
>
> Sorry I don't understand, can you elaborate please?
> Note I haven't changed much in there, just variable
> rename and changed the condition within if: s/== -1/< 0/.
>
You use 'ret' instead of 'err', but remain using 'if (err < 0)',
and missing '{' at the end of if statement.
hw/9pfs/virtio-9p-proxy.c: In function ‘proxy_preadv’:
hw/9pfs/virtio-9p-proxy.c:700: error: ‘err’ undeclared (first use in this function)
hw/9pfs/virtio-9p-proxy.c:700: error: (Each undeclared identifier is reported only once
hw/9pfs/virtio-9p-proxy.c:700: error: for each function it appears in.)
hw/9pfs/virtio-9p-proxy.c:702: warning: control reaches end of non-void function
hw/9pfs/virtio-9p-proxy.c: At top level:
hw/9pfs/virtio-9p-proxy.c:702: error: expected identifier or ‘(’ before ‘else’
hw/9pfs/virtio-9p-proxy.c:706: error: expected identifier or ‘(’ before ‘}’ token
make: *** [hw/9pfs/virtio-9p-proxy.o] Error 1
Regards,
-Gonglei
> (BTW, a code fragment can't be confused, it might be
> confusing I think, with a reader being confused.
> A confused code is um.. something -- a code who doesn't
> know what to do... ;) Sorry can't resist ;)
>
> Thanks,
>
> /mjt
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] 9pfs-proxy: tiny cleanups in proxy_pwritev and proxy_preadv
2015-03-10 5:54 [Qemu-devel] [PATCH] 9pfs-proxy: tiny cleanups in proxy_pwritev and proxy_preadv Michael Tokarev
2015-03-10 7:15 ` Gonglei
@ 2015-03-10 17:23 ` Aneesh Kumar K.V
2015-03-12 6:30 ` Michael Tokarev
1 sibling, 1 reply; 6+ messages in thread
From: Aneesh Kumar K.V @ 2015-03-10 17:23 UTC (permalink / raw)
To: Michael Tokarev, qemu-devel; +Cc: qemu-trivial
Michael Tokarev <mjt@tls.msk.ru> writes:
> Don't compare syscall return with -1, use "<0" condition.
> Don't introduce useless local variables when we already
> have similar variable
> Rename local variable to be consistent with other usages
>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> hw/9pfs/virtio-9p-proxy.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
> index 59c7445..a01804a 100644
> --- a/hw/9pfs/virtio-9p-proxy.c
> +++ b/hw/9pfs/virtio-9p-proxy.c
> @@ -696,9 +696,9 @@ static ssize_t proxy_preadv(FsContext *ctx, V9fsFidOpenState *fs,
> #ifdef CONFIG_PREADV
> return preadv(fs->fd, iov, iovcnt, offset);
> #else
> - int err = lseek(fs->fd, offset, SEEK_SET);
> - if (err == -1) {
> - return err;
> + int ret = lseek(fs->fd, offset, SEEK_SET);
> + if (err < 0)
> + return ret;
> } else {
> return readv(fs->fd, iov, iovcnt);
> }
I am not sure this is needed, whether to use int err or int ret as the
variable name is simply a matter of preference for the author. Also did
you compile test the above ? (note: int ret followed by a check with
variable name 'err').
> @@ -714,10 +714,8 @@ static ssize_t proxy_pwritev(FsContext *ctx, V9fsFidOpenState *fs,
> #ifdef CONFIG_PREADV
> ret = pwritev(fs->fd, iov, iovcnt, offset);
> #else
> - int err = lseek(fs->fd, offset, SEEK_SET);
> - if (err == -1) {
> - return err;
> - } else {
> + ret = lseek(fs->fd, offset, SEEK_SET);
> + if (ret >= 0) {
> ret = writev(fs->fd, iov, iovcnt);
> }
> #endif
-aneesh
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] 9pfs-proxy: tiny cleanups in proxy_pwritev and proxy_preadv
2015-03-10 17:23 ` Aneesh Kumar K.V
@ 2015-03-12 6:30 ` Michael Tokarev
0 siblings, 0 replies; 6+ messages in thread
From: Michael Tokarev @ 2015-03-12 6:30 UTC (permalink / raw)
To: Aneesh Kumar K.V, qemu-devel; +Cc: qemu-trivial
10.03.2015 20:23, Aneesh Kumar K.V wrote:
[]>
> I am not sure this is needed, whether to use int err or int ret as the
> variable name is simply a matter of preference for the author.
We have 2 filesystem methods in here, read and write, one near another,
which are written by the same author (but one of them has been later
extended a bit, adding another variable). This patch makes them similar
again.
> Also did
> you compile test the above ? (note: int ret followed by a check with
> variable name 'err').
Well yes. It is a forgotten git commit. Ofcourse I verified the result,
I just forgot to commit because I was distracted by something else, hence
sent a wrong patch. I'll resend it.
/mjt
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-03-12 6:30 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-10 5:54 [Qemu-devel] [PATCH] 9pfs-proxy: tiny cleanups in proxy_pwritev and proxy_preadv Michael Tokarev
2015-03-10 7:15 ` Gonglei
2015-03-10 7:20 ` Michael Tokarev
2015-03-10 7:27 ` Gonglei
2015-03-10 17:23 ` Aneesh Kumar K.V
2015-03-12 6:30 ` Michael Tokarev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).