[Mesa-dev] [PATCH v2] egl/dri2: use drm macros to construct device name

Matt Turner mattst88 at gmail.com
Tue Apr 1 10:32:34 PDT 2014


On Tue, Apr 1, 2014 at 10:26 AM, Emil Velikov <emil.l.velikov at gmail.com> wrote:
> On 23/03/14 04:53, Jonathan Gray wrote:
>> Don't hardcode /dev/dri/card0 but instead use the drm
>> macros which allows the correct /dev/drm0 device to be
>> opened on OpenBSD.
>>
>> v2: use snprintf and fallback to /dev/dri/card0
>> suggested by Emil Velikov.
>>
>> Signed-off-by: Jonathan Gray <jsg at jsg.id.au>
>> ---
>>  src/egl/drivers/dri2/platform_drm.c | 6 +++++-
>>  1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
>> index 2f7edb9..964ac5a 100644
>> --- a/src/egl/drivers/dri2/platform_drm.c
>> +++ b/src/egl/drivers/dri2/platform_drm.c
>> @@ -492,7 +492,11 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
>>
>>     gbm = disp->PlatformDisplay;
>>     if (gbm == NULL) {
>> -      fd = open("/dev/dri/card0", O_RDWR);
>> +      char buf[64];
>> +      if (snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, 0) != -1)
> If I'm reading things correctly, one should check against the correct length
> as snprintf may return smaller value on failure, and -1 when it's completely
> stuffed.

snprintf returns -1 on error, and the number of characters it
generated pre-truncation, so indeed this code needs a fixup.


More information about the mesa-dev mailing list