mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Colin Ian King <colin.king@canonical.com>
To: Emil Velikov <emil.l.velikov@gmail.com>,
	Ilia Mirkin <imirkin@alum.mit.edu>
Cc: Ben Skeggs <bskeggs@redhat.com>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] drm/nouveau: usif_ioctl: ensure returns are initialized
Date: Wed, 01 Jul 2015 18:18:18 +0100	[thread overview]
Message-ID: <559420DA.3010401@canonical.com> (raw)
In-Reply-To: <CACvgo52S5gxzOsckG6iretST-mMeBqKhNTREbpmqJGWD26h-Rg@mail.gmail.com>

On 01/07/15 18:12, Emil Velikov wrote:
> On 1 July 2015 at 17:56, Ilia Mirkin <imirkin@alum.mit.edu> wrote:
>> On Wed, Jul 1, 2015 at 12:51 PM, Colin King <colin.king@canonical.com> wrote:
>>> From: Colin Ian King <colin.king@canonical.com>
>>>
>>> Various usif_ioctl helper functions do not initialize the
>>> return variable ret and some of the error handling return
>>> paths just return garbage values that were on the stack (or
>>> in a register).  I believe that in all the cases, the
>>> initial ret variable should be set to -EINVAL and subsequent
>>> paths through these helper functions set it appropriately
>>> otherwise.
>>>
>>> Found via static analysis using cppcheck:
>>>
>>> [drivers/gpu/drm/nouveau/nouveau_usif.c:138]:
>>>     (error) Uninitialized variable: ret
>>
>> It sure would seem that way, wouldn't it?
>>
>> #define nvif_unpack(d,vl,vh,m) ({                                              \
>>         if ((vl) == 0 || ret == -ENOSYS) {                                     \
>>                 int _size = sizeof(d);                                         \
>>                 if (_size <= size && (d).version >= (vl) &&                    \
>>                                      (d).version <= (vh)) {                    \
>>                         data = (u8 *)data + _size;                             \
>>                         size = size - _size;                                   \
>>                         ret = ((m) || !size) ? 0 : -E2BIG;                     \
>>                 } else {                                                       \
>>                         ret = -ENOSYS;                                         \
>>                 }                                                              \
>>         }                                                                      \
>>         (ret == 0);                                                            \
>> })
>>
>> So actually it does get initialized, and I guess cppcheck doesn't know
>> about macros?

Hrm, what about the case when ((vl) == 0 || ret == -ENOSYS) is false,
where is ret being set in that case?

>>
> I think I'm having deja-vu, but I do recall a similar mention to Ben.
> Although in my defence I've assumed that nvif_unpack was a function,
> as macros normally are normally all caps. Seems like the patch that
> capitalises nvif_unpack never made it upstream :'-(
> 
> Cheers,
> Emil
> 


  reply	other threads:[~2015-07-01 17:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-01 16:51 Colin King
2015-07-01 16:56 ` Ilia Mirkin
2015-07-01 17:12   ` Emil Velikov
2015-07-01 17:18     ` Colin Ian King [this message]
2015-07-01 17:37       ` Ilia Mirkin
2015-07-01 17:59         ` Emil Velikov
2015-07-01 18:06           ` Ilia Mirkin

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=559420DA.3010401@canonical.com \
    --to=colin.king@canonical.com \
    --cc=bskeggs@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emil.l.velikov@gmail.com \
    --cc=imirkin@alum.mit.edu \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®