All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: George Dunlap <george.dunlap@citrix.com>,
	Ian Jackson <iwj@xenproject.org>, Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH][4.15] gnttab: work around "may be used uninitialized" warning
Date: Fri, 12 Mar 2021 14:29:31 +0100	[thread overview]
Message-ID: <1167c6a5-4d76-8803-99a5-33121aa82b3a@suse.com> (raw)
In-Reply-To: <4722bb38-387a-7bd2-12fc-87dcbde48d4f@citrix.com>

On 12.03.2021 14:25, Andrew Cooper wrote:
> On 12/03/2021 13:08, Jan Beulich wrote:
>> On 12.03.2021 12:32, Andrew Cooper wrote:
>>> On 10/03/2021 10:13, Jan Beulich wrote:
>>>> Sadly I was wrong to suggest dropping vaddrs' initializer during review
>>>> of v2 of the patch introducing this code. gcc 4.3 can't cope.
>>>>
>>>> Fixes: 52531c734ea1 ("xen/gnttab: Rework resource acquisition")
>>>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>>>>
>>>> --- a/xen/common/grant_table.c
>>>> +++ b/xen/common/grant_table.c
>>>> @@ -4026,7 +4026,7 @@ int gnttab_acquire_resource(
>>>>      struct grant_table *gt = d->grant_table;
>>>>      unsigned int i, final_frame;
>>>>      mfn_t tmp;
>>>> -    void **vaddrs;
>>>> +    void **vaddrs = NULL;
>>>>      int rc = -EINVAL;
>>>>  
>>>>      if ( !nr_frames )
>>> in v1, there was a companion check.
>>>
>>> diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
>>> index f937c1d350..2bb07f129f 100644
>>> --- a/xen/common/grant_table.c
>>> +++ b/xen/common/grant_table.c
>>> @@ -4059,6 +4059,16 @@ int gnttab_acquire_resource(
>>>      if ( rc )
>>>          goto out;
>>>  
>>> +    /*
>>> +     * Some older toolchains can't spot that vaddrs is non-NULL on
>>> non-error
>>> +     * paths.  Leave some runtime safety.
>>> +     */
>>> +    if ( !vaddrs )
>>> +    {
>>> +        ASSERT_UNREACHABLE();
>>> +        goto out;
>>> +    }
>>> +
>>>      for ( i = 0; i < nr_frames; ++i )
>>>          mfn_list[i] = virt_to_mfn(vaddrs[frame + i]);
>> Oh, I didn't realize this. Will add, but did you really mean to
>> have the function return success in this case (on a release
>> build)? I'd be inclined to put it ahead of if "if ( rc )" and
>> set rc (to e.g. -ENODATA) in this case.
> 
> Oh - quite right.  Returning 0 here will hit the assertion/failsafe
> protecting against livelock.
> 
> I'd be tempted to chose -EINVAL because the only plausible way to get
> here is a bad id, and that path should have errored out earlier.

As you may have seen, I've chosen to stick to ENODATA. This error,
should it ever get raised, would better be easily distinguishable
from an ordinary -EINVAL.

Jan


      reply	other threads:[~2021-03-12 13:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-10 10:13 [PATCH][4.15] gnttab: work around "may be used uninitialized" warning Jan Beulich
2021-03-10 14:58 ` Julien Grall
2021-03-10 16:21   ` Jan Beulich
2021-03-10 17:52     ` Julien Grall
2021-03-11  8:09       ` Jan Beulich
2021-03-11  8:25         ` Roger Pau Monné
2021-03-11  8:33           ` Jan Beulich
2021-03-12 10:04       ` Ian Jackson
2021-03-12 10:13         ` Jan Beulich
2021-03-12 10:29           ` Ian Jackson
2021-03-12 11:05             ` Jan Beulich
2021-03-12 15:59         ` Jan Beulich
2021-03-12 16:30           ` Ian Jackson
2021-03-12 11:32 ` Andrew Cooper
2021-03-12 13:08   ` Jan Beulich
2021-03-12 13:18     ` Jan Beulich
2021-03-12 13:20       ` Andrew Cooper
2021-03-12 13:25     ` Andrew Cooper
2021-03-12 13:29       ` Jan Beulich [this message]

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=1167c6a5-4d76-8803-99a5-33121aa82b3a@suse.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=iwj@xenproject.org \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.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.