Re: [PATCH] drm/nouveau: usif_ioctl: ensure returns are initialized

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jul 1, 2015 at 1:18 PM, Colin Ian King <colin.king@xxxxxxxxxxxxx> wrote:
> On 01/07/15 18:12, Emil Velikov wrote:
>> On 1 July 2015 at 17:56, Ilia Mirkin <imirkin@xxxxxxxxxxxx> wrote:
>>> On Wed, Jul 1, 2015 at 12:51 PM, Colin King <colin.king@xxxxxxxxxxxxx> wrote:
>>>> From: Colin Ian King <colin.king@xxxxxxxxxxxxx>
>>>>
>>>> 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?

Is that actually the case for any of the callsites? gcc would complain
about that...
_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux