* [PATCH] 9pfs: Fix some return statements in the synth backend
@ 2022-11-24 15:58 Greg Kurz
2022-11-26 13:47 ` Christian Schoenebeck
2022-11-28 7:35 ` Markus Armbruster
0 siblings, 2 replies; 6+ messages in thread
From: Greg Kurz @ 2022-11-24 15:58 UTC (permalink / raw)
To: qemu-devel; +Cc: Christian Schoenebeck, Greg Kurz, Markus Armbruster
The qemu_v9fs_synth_mkdir() and qemu_v9fs_synth_add_file() functions
currently return a positive errno value on failure. This causes
checkpatch.pl to spit several errors like the one below:
ERROR: return of an errno should typically be -ve (return -EAGAIN)
#79: FILE: hw/9pfs/9p-synth.c:79:
+ return EAGAIN;
Simply change the sign. This has no consequence since callers
assert() the returned value to be equal to 0.
While here also get rid of the uneeded ret variables as suggested
by return_directly.cocci.
Reported-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Greg Kurz <groug@kaod.org>
---
hw/9pfs/9p-synth.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
index 1c5813e4ddc6..f62c40b639fc 100644
--- a/hw/9pfs/9p-synth.c
+++ b/hw/9pfs/9p-synth.c
@@ -72,14 +72,13 @@ static V9fsSynthNode *v9fs_add_dir_node(V9fsSynthNode *parent, int mode,
int qemu_v9fs_synth_mkdir(V9fsSynthNode *parent, int mode,
const char *name, V9fsSynthNode **result)
{
- int ret;
V9fsSynthNode *node, *tmp;
if (!synth_fs) {
- return EAGAIN;
+ return -EAGAIN;
}
if (!name || (strlen(name) >= NAME_MAX)) {
- return EINVAL;
+ return -EINVAL;
}
if (!parent) {
parent = &synth_root;
@@ -87,8 +86,7 @@ int qemu_v9fs_synth_mkdir(V9fsSynthNode *parent, int mode,
QEMU_LOCK_GUARD(&synth_mutex);
QLIST_FOREACH(tmp, &parent->child, sibling) {
if (!strcmp(tmp->name, name)) {
- ret = EEXIST;
- return ret;
+ return -EEXIST;
}
}
/* Add the name */
@@ -98,22 +96,20 @@ int qemu_v9fs_synth_mkdir(V9fsSynthNode *parent, int mode,
v9fs_add_dir_node(node, node->attr->mode, ".",
node->attr, node->attr->inode);
*result = node;
- ret = 0;
- return ret;
+ return 0;
}
int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
const char *name, v9fs_synth_read read,
v9fs_synth_write write, void *arg)
{
- int ret;
V9fsSynthNode *node, *tmp;
if (!synth_fs) {
- return EAGAIN;
+ return -EAGAIN;
}
if (!name || (strlen(name) >= NAME_MAX)) {
- return EINVAL;
+ return -EINVAL;
}
if (!parent) {
parent = &synth_root;
@@ -122,8 +118,7 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
QEMU_LOCK_GUARD(&synth_mutex);
QLIST_FOREACH(tmp, &parent->child, sibling) {
if (!strcmp(tmp->name, name)) {
- ret = EEXIST;
- return ret;
+ return -EEXIST;
}
}
/* Add file type and remove write bits */
@@ -138,8 +133,7 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
node->private = arg;
pstrcpy(node->name, sizeof(node->name), name);
QLIST_INSERT_HEAD_RCU(&parent->child, node, sibling);
- ret = 0;
- return ret;
+ return 0;
}
static void synth_fill_statbuf(V9fsSynthNode *node, struct stat *stbuf)
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] 9pfs: Fix some return statements in the synth backend
2022-11-24 15:58 [PATCH] 9pfs: Fix some return statements in the synth backend Greg Kurz
@ 2022-11-26 13:47 ` Christian Schoenebeck
2022-11-28 7:35 ` Markus Armbruster
1 sibling, 0 replies; 6+ messages in thread
From: Christian Schoenebeck @ 2022-11-26 13:47 UTC (permalink / raw)
To: qemu-devel; +Cc: Greg Kurz, Markus Armbruster
On Thursday, November 24, 2022 4:58:38 PM CET Greg Kurz wrote:
> The qemu_v9fs_synth_mkdir() and qemu_v9fs_synth_add_file() functions
> currently return a positive errno value on failure. This causes
> checkpatch.pl to spit several errors like the one below:
>
> ERROR: return of an errno should typically be -ve (return -EAGAIN)
> #79: FILE: hw/9pfs/9p-synth.c:79:
> + return EAGAIN;
>
> Simply change the sign. This has no consequence since callers
> assert() the returned value to be equal to 0.
>
> While here also get rid of the uneeded ret variables as suggested
> by return_directly.cocci.
>
> Reported-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
> hw/9pfs/9p-synth.c | 22 ++++++++--------------
> 1 file changed, 8 insertions(+), 14 deletions(-)
Queued on 9p.next:
https://github.com/cschoenebeck/qemu/commits/9p.next
I would have expected more locations like that.
Thanks!
Best regards,
Christian Schoenebeck
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] 9pfs: Fix some return statements in the synth backend
2022-11-24 15:58 [PATCH] 9pfs: Fix some return statements in the synth backend Greg Kurz
2022-11-26 13:47 ` Christian Schoenebeck
@ 2022-11-28 7:35 ` Markus Armbruster
2022-11-28 9:37 ` Greg Kurz
1 sibling, 1 reply; 6+ messages in thread
From: Markus Armbruster @ 2022-11-28 7:35 UTC (permalink / raw)
To: Greg Kurz; +Cc: qemu-devel, Christian Schoenebeck
Greg Kurz <groug@kaod.org> writes:
> The qemu_v9fs_synth_mkdir() and qemu_v9fs_synth_add_file() functions
> currently return a positive errno value on failure. This causes
> checkpatch.pl to spit several errors like the one below:
>
> ERROR: return of an errno should typically be -ve (return -EAGAIN)
> #79: FILE: hw/9pfs/9p-synth.c:79:
> + return EAGAIN;
>
> Simply change the sign. This has no consequence since callers
> assert() the returned value to be equal to 0.
Out of curiosity: why is assert() appropriate?
> While here also get rid of the uneeded ret variables as suggested
> by return_directly.cocci.
>
> Reported-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] 9pfs: Fix some return statements in the synth backend
2022-11-28 7:35 ` Markus Armbruster
@ 2022-11-28 9:37 ` Greg Kurz
2022-11-28 10:18 ` Markus Armbruster
0 siblings, 1 reply; 6+ messages in thread
From: Greg Kurz @ 2022-11-28 9:37 UTC (permalink / raw)
To: Markus Armbruster; +Cc: qemu-devel, Christian Schoenebeck
On Mon, 28 Nov 2022 08:35:22 +0100
Markus Armbruster <armbru@redhat.com> wrote:
> Greg Kurz <groug@kaod.org> writes:
>
> > The qemu_v9fs_synth_mkdir() and qemu_v9fs_synth_add_file() functions
> > currently return a positive errno value on failure. This causes
> > checkpatch.pl to spit several errors like the one below:
> >
> > ERROR: return of an errno should typically be -ve (return -EAGAIN)
> > #79: FILE: hw/9pfs/9p-synth.c:79:
> > + return EAGAIN;
> >
> > Simply change the sign. This has no consequence since callers
> > assert() the returned value to be equal to 0.
>
> Out of curiosity: why is assert() appropriate?
>
Most of the code base comes from the original synth backend which
was designed to expose QEMU internals to the guest using 9p. The
hope of the virtio-9p authors was that each QEMU subsystem would
create its own tree using these two functions (note that they
are declared extern). Of course these never happened and the synth
backend remained nearly dead code for years, until finally it got
re-used to implement 9p qtest. In this context, failure to create a
synthetic directory or file means the related test has a bug (e.g.
messing with the paths used by some other test). This code likely
needs improvements but we never got to it.
> > While here also get rid of the uneeded ret variables as suggested
> > by return_directly.cocci.
> >
> > Reported-by: Markus Armbruster <armbru@redhat.com>
> > Signed-off-by: Greg Kurz <groug@kaod.org>
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] 9pfs: Fix some return statements in the synth backend
2022-11-28 9:37 ` Greg Kurz
@ 2022-11-28 10:18 ` Markus Armbruster
2022-11-28 14:21 ` Christian Schoenebeck
0 siblings, 1 reply; 6+ messages in thread
From: Markus Armbruster @ 2022-11-28 10:18 UTC (permalink / raw)
To: Greg Kurz; +Cc: qemu-devel, Christian Schoenebeck
Greg Kurz <groug@kaod.org> writes:
> On Mon, 28 Nov 2022 08:35:22 +0100
> Markus Armbruster <armbru@redhat.com> wrote:
>
>> Greg Kurz <groug@kaod.org> writes:
>>
>> > The qemu_v9fs_synth_mkdir() and qemu_v9fs_synth_add_file() functions
>> > currently return a positive errno value on failure. This causes
>> > checkpatch.pl to spit several errors like the one below:
>> >
>> > ERROR: return of an errno should typically be -ve (return -EAGAIN)
>> > #79: FILE: hw/9pfs/9p-synth.c:79:
>> > + return EAGAIN;
>> >
>> > Simply change the sign. This has no consequence since callers
>> > assert() the returned value to be equal to 0.
>>
>> Out of curiosity: why is assert() appropriate?
>>
>
> Most of the code base comes from the original synth backend which
> was designed to expose QEMU internals to the guest using 9p. The
> hope of the virtio-9p authors was that each QEMU subsystem would
> create its own tree using these two functions (note that they
> are declared extern). Of course these never happened and the synth
> backend remained nearly dead code for years, until finally it got
> re-used to implement 9p qtest. In this context, failure to create a
> synthetic directory or file means the related test has a bug (e.g.
> messing with the paths used by some other test). This code likely
> needs improvements but we never got to it.
I was about to suggest putting this in a file comment, but then I saw
/*
* Not so fast! You might want to read the 9p developer docs first:
* https://wiki.qemu.org/Documentation/9p
*/
and behind the link, there's a paragraph "3. synth fs driver".
Perhaps a brief note on the use of assert() in synth_init() would still
make sense. Up to you.
Thanks!
[...]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] 9pfs: Fix some return statements in the synth backend
2022-11-28 10:18 ` Markus Armbruster
@ 2022-11-28 14:21 ` Christian Schoenebeck
0 siblings, 0 replies; 6+ messages in thread
From: Christian Schoenebeck @ 2022-11-28 14:21 UTC (permalink / raw)
To: Greg Kurz, qemu-devel, Markus Armbruster
On Monday, November 28, 2022 11:18:48 AM CET Markus Armbruster wrote:
> Greg Kurz <groug@kaod.org> writes:
>
> > On Mon, 28 Nov 2022 08:35:22 +0100
> > Markus Armbruster <armbru@redhat.com> wrote:
> >
> >> Greg Kurz <groug@kaod.org> writes:
> >>
> >> > The qemu_v9fs_synth_mkdir() and qemu_v9fs_synth_add_file() functions
> >> > currently return a positive errno value on failure. This causes
> >> > checkpatch.pl to spit several errors like the one below:
> >> >
> >> > ERROR: return of an errno should typically be -ve (return -EAGAIN)
> >> > #79: FILE: hw/9pfs/9p-synth.c:79:
> >> > + return EAGAIN;
> >> >
> >> > Simply change the sign. This has no consequence since callers
> >> > assert() the returned value to be equal to 0.
> >>
> >> Out of curiosity: why is assert() appropriate?
> >>
> >
> > Most of the code base comes from the original synth backend which
> > was designed to expose QEMU internals to the guest using 9p. The
> > hope of the virtio-9p authors was that each QEMU subsystem would
> > create its own tree using these two functions (note that they
> > are declared extern). Of course these never happened and the synth
> > backend remained nearly dead code for years, until finally it got
> > re-used to implement 9p qtest. In this context, failure to create a
> > synthetic directory or file means the related test has a bug (e.g.
> > messing with the paths used by some other test). This code likely
> > needs improvements but we never got to it.
>
> I was about to suggest putting this in a file comment, but then I saw
>
> /*
> * Not so fast! You might want to read the 9p developer docs first:
> * https://wiki.qemu.org/Documentation/9p
> */
>
> and behind the link, there's a paragraph "3. synth fs driver".
>
> Perhaps a brief note on the use of assert() in synth_init() would still
> make sense. Up to you.
Like what comment would you expect there?
The synth driver is a simplified hack fs driver with hard coded directories &
files, only used for 9p protocol conformance test cases.
Best regards,
Christian Schoenebeck
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-11-28 14:23 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-24 15:58 [PATCH] 9pfs: Fix some return statements in the synth backend Greg Kurz
2022-11-26 13:47 ` Christian Schoenebeck
2022-11-28 7:35 ` Markus Armbruster
2022-11-28 9:37 ` Greg Kurz
2022-11-28 10:18 ` Markus Armbruster
2022-11-28 14:21 ` Christian Schoenebeck
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).