From: Emil Velikov <emil.l.velikov@gmail.com>
To: Ilia Mirkin <imirkin@alum.mit.edu>
Cc: emil.l.velikov@gmail.com,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 1/3] nouveau: cleanup error handling during nouveau_device_wrap
Date: Thu, 13 Mar 2014 01:04:40 +0000 [thread overview]
Message-ID: <53210428.3030209@gmail.com> (raw)
In-Reply-To: <CAKb7Uvjiq_qhRqprGimsnk56qsTJ7emZGVPd+b3BMM4Vwa9J3A@mail.gmail.com>
On 13/03/14 00:45, Ilia Mirkin wrote:
> On Wed, Mar 12, 2014 at 4:45 PM, Emil Velikov <emil.l.velikov@gmail.com> wrote:
>> In theory it's possible for any of the nouveau_getparam calls to
>> fail whist the last one being successful.
>>
>> Thus at least one of the following (hard requirements) drmVersion,
>> chipset and vram/gart memory size will be filled with garbage and
>> sent to the userspace drivers.
>
> What was wrong with the old logic again? Except annoying indentation?
>
> ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_CHIPSET_ID, &chipset);
> if (ret == 0)
> ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_FB_SIZE, &vram);
> if (ret == 0)
> ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_AGP_SIZE, &gart);
> if (ret) {
> nouveau_device_del(&dev);
> return ret;
> }
>
> It will only run each successive getparam if the previous one succeeded...
>
Good point, the lovely indentation got me. So it seems only !ver
handling is needed.
>
>>
>> Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
>> ---
>> nouveau/nouveau.c | 30 +++++++++++++++++++-----------
>> 1 file changed, 19 insertions(+), 11 deletions(-)
>>
>> diff --git a/nouveau/nouveau.c b/nouveau/nouveau.c
>> index ee7893b..d6013db 100644
>> --- a/nouveau/nouveau.c
>> +++ b/nouveau/nouveau.c
>> @@ -88,27 +88,32 @@ nouveau_device_wrap(int fd, int close, struct nouveau_device **pdev)
>> nvdev->base.fd = fd;
>>
>> ver = drmGetVersion(fd);
>> - if (ver) dev->drm_version = (ver->version_major << 24) |
>> - (ver->version_minor << 8) |
>> - ver->version_patchlevel;
>> + if (!ver) {
>> + ret = -errno;
>> + goto error;
>> + }
>> +
>> + dev->drm_version = (ver->version_major << 24) |
>> + (ver->version_minor << 8) |
>> + ver->version_patchlevel;
>> drmFreeVersion(ver);
>>
>> if ( dev->drm_version != 0x00000010 &&
>> (dev->drm_version < 0x01000000 ||
>> dev->drm_version >= 0x02000000)) {
>> - nouveau_device_del(&dev);
>> - return -EINVAL;
>> + ret = -EINVAL;
>> + goto error;
>> }
>>
>> ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_CHIPSET_ID, &chipset);
>> - if (ret == 0)
>> + if (ret)
>> + goto error;
>> ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_FB_SIZE, &vram);
>> - if (ret == 0)
>> + if (ret)
>> + goto error;
>> ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_AGP_SIZE, &gart);
>> - if (ret) {
>> - nouveau_device_del(&dev);
>> - return ret;
>> - }
>> + if (ret)
>> + goto error;
>>
>> ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_HAS_BO_USAGE, &bousage);
>> if (ret == 0)
>> @@ -139,6 +144,9 @@ nouveau_device_wrap(int fd, int close, struct nouveau_device **pdev)
>>
>> *pdev = &nvdev->base;
>> return 0;
>> +error:
>> + nouveau_device_del(&dev);
>> + return -ret;
>
> you mean 'ret' of course.
>
Yikes, thanks.
-Emil
>> }
>>
>> int
>> --
>> 1.9.0
>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2014-03-13 1:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-12 20:45 [PATCH 1/3] nouveau: cleanup error handling during nouveau_device_wrap Emil Velikov
2014-03-12 20:45 ` [PATCH 2/3] nouveau: sanitise NOUVEAU_LIBDRM_*_LIMIT_PERCENT input Emil Velikov
2014-03-13 0:49 ` Ilia Mirkin
2014-03-13 1:11 ` Emil Velikov
2014-03-12 20:45 ` [PATCH 3/3] freedreno: do not leak drmVersion Emil Velikov
2014-03-13 1:01 ` Rob Clark
2014-03-13 0:45 ` [PATCH 1/3] nouveau: cleanup error handling during nouveau_device_wrap Ilia Mirkin
2014-03-13 1:04 ` Emil Velikov [this message]
2014-03-13 1:05 ` Ilia Mirkin
2014-03-13 1:24 ` Emil Velikov
2014-03-13 1:27 ` 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=53210428.3030209@gmail.com \
--to=emil.l.velikov@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=imirkin@alum.mit.edu \
/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.