Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753371AbbGASGL (ORCPT ); Wed, 1 Jul 2015 14:06:11 -0400 Received: from mail-ob0-f180.google.com ([209.85.214.180]:32783 "EHLO mail-ob0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752671AbbGASGD (ORCPT ); Wed, 1 Jul 2015 14:06:03 -0400 MIME-Version: 1.0 In-Reply-To: References: <1435769495-2025-1-git-send-email-colin.king@canonical.com> <559420DA.3010401@canonical.com> Date: Wed, 1 Jul 2015 14:06:02 -0400 X-Google-Sender-Auth: ah7H3awjLyXn73bVcn7P2NB0DgE Message-ID: Subject: Re: [PATCH] drm/nouveau: usif_ioctl: ensure returns are initialized From: Ilia Mirkin To: Emil Velikov Cc: Colin Ian King , Ben Skeggs , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3087 Lines: 59 On Wed, Jul 1, 2015 at 1:59 PM, Emil Velikov wrote: > On 1 July 2015 at 18:37, Ilia Mirkin wrote: >> On Wed, Jul 1, 2015 at 1:18 PM, Colin Ian King wrote: >>> On 01/07/15 18:12, Emil Velikov wrote: >>>> On 1 July 2015 at 17:56, Ilia Mirkin wrote: >>>>> On Wed, Jul 1, 2015 at 12:51 PM, Colin King wrote: >>>>>> From: Colin Ian King >>>>>> >>>>>> 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... > There is one: > > drm/nouveau/nvkm/engine/disp/nv50.c: if (nvif_unpack(args->v1, 1, 1, true)) > > Seems like a recent addition though, I don't recall it with back when > was introduced. It follows a call to nvif_unpack(0) though, which will initialize ret. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/