* [PATCH libdrm v2] libdrm: Use readdir instead of readdir_r to avoid build warnings
@ 2018-03-20 17:48 Emil Velikov
2018-03-20 18:17 ` Eric Engestrom
0 siblings, 1 reply; 4+ messages in thread
From: Emil Velikov @ 2018-03-20 17:48 UTC (permalink / raw)
To: dri-devel; +Cc: Robert Foss, emil.l.velikov, Stefan Schake
From: John Stultz <john.stultz@linaro.org>
Building libdrm under AOSP, we see the following build warning:
external/libdrm/xf86drm.c:2861:12: warning: 'readdir_r' is deprecated: readdir_r is deprecated; use readdir instead [-Wdeprecated-declarations]
while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
^
Building on Linux with glibc produces the same warning.
Thus, this patch replaces readdir_r with readdir.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102031
Cc: Robert Foss <robert.foss@collabora.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Stefan Schake <stschake@gmail.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Eric Engestrom <eric.engestrom@imgtec.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
[Emil Velikov: remove unused variables, Eric]
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
---
xf86drm.c | 22 +++-------------------
1 file changed, 3 insertions(+), 19 deletions(-)
diff --git a/xf86drm.c b/xf86drm.c
index 9328bf5a..97f87e02 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2822,12 +2822,11 @@ static char *drmGetMinorNameForFD(int fd, int type)
{
#ifdef __linux__
DIR *sysdir;
- struct dirent *pent, *ent;
+ struct dirent *ent;
struct stat sbuf;
const char *name = drmGetMinorName(type);
int len;
char dev_name[64], buf[64];
- long name_max;
int maj, min;
if (!name)
@@ -2850,30 +2849,16 @@ static char *drmGetMinorNameForFD(int fd, int type)
if (!sysdir)
return NULL;
- name_max = fpathconf(dirfd(sysdir), _PC_NAME_MAX);
- if (name_max == -1)
- goto out_close_dir;
-
- pent = malloc(offsetof(struct dirent, d_name) + name_max + 1);
- if (pent == NULL)
- goto out_close_dir;
-
- while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
+ while ((ent = readdir(sysdir))) {
if (strncmp(ent->d_name, name, len) == 0) {
snprintf(dev_name, sizeof(dev_name), DRM_DIR_NAME "/%s",
ent->d_name);
- free(pent);
closedir(sysdir);
-
return strdup(dev_name);
}
}
-
- free(pent);
-
-out_close_dir:
- closedir(sysdir);
+ return NULL;
#else
struct stat sbuf;
char buf[PATH_MAX + 1];
@@ -2914,7 +2899,6 @@ out_close_dir:
return strdup(buf);
#endif
- return NULL;
}
char *drmGetPrimaryDeviceNameFromFd(int fd)
--
2.16.0
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH libdrm v2] libdrm: Use readdir instead of readdir_r to avoid build warnings
2018-03-20 17:48 [PATCH libdrm v2] libdrm: Use readdir instead of readdir_r to avoid build warnings Emil Velikov
@ 2018-03-20 18:17 ` Eric Engestrom
2018-03-22 16:51 ` Emil Velikov
0 siblings, 1 reply; 4+ messages in thread
From: Eric Engestrom @ 2018-03-20 18:17 UTC (permalink / raw)
To: Emil Velikov; +Cc: Robert Foss, dri-devel, Stefan Schake
On Tuesday, 2018-03-20 17:48:23 +0000, Emil Velikov wrote:
> From: John Stultz <john.stultz@linaro.org>
>
> Building libdrm under AOSP, we see the following build warning:
> external/libdrm/xf86drm.c:2861:12: warning: 'readdir_r' is deprecated: readdir_r is deprecated; use readdir instead [-Wdeprecated-declarations]
> while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
> ^
>
> Building on Linux with glibc produces the same warning.
> Thus, this patch replaces readdir_r with readdir.
>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102031
> Cc: Robert Foss <robert.foss@collabora.com>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Stefan Schake <stschake@gmail.com>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Eric Engestrom <eric.engestrom@imgtec.com>
> Signed-off-by: John Stultz <john.stultz@linaro.org>
> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
> [Emil Velikov: remove unused variables, Eric]
> Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
I think that's pretty much exactly the patch I have at home :)
(and that I forgot to send out last night)
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
> ---
> xf86drm.c | 22 +++-------------------
> 1 file changed, 3 insertions(+), 19 deletions(-)
>
> diff --git a/xf86drm.c b/xf86drm.c
> index 9328bf5a..97f87e02 100644
> --- a/xf86drm.c
> +++ b/xf86drm.c
> @@ -2822,12 +2822,11 @@ static char *drmGetMinorNameForFD(int fd, int type)
> {
> #ifdef __linux__
> DIR *sysdir;
> - struct dirent *pent, *ent;
> + struct dirent *ent;
> struct stat sbuf;
> const char *name = drmGetMinorName(type);
> int len;
> char dev_name[64], buf[64];
> - long name_max;
> int maj, min;
>
> if (!name)
> @@ -2850,30 +2849,16 @@ static char *drmGetMinorNameForFD(int fd, int type)
> if (!sysdir)
> return NULL;
>
> - name_max = fpathconf(dirfd(sysdir), _PC_NAME_MAX);
> - if (name_max == -1)
> - goto out_close_dir;
> -
> - pent = malloc(offsetof(struct dirent, d_name) + name_max + 1);
> - if (pent == NULL)
> - goto out_close_dir;
> -
> - while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
> + while ((ent = readdir(sysdir))) {
> if (strncmp(ent->d_name, name, len) == 0) {
> snprintf(dev_name, sizeof(dev_name), DRM_DIR_NAME "/%s",
> ent->d_name);
>
> - free(pent);
> closedir(sysdir);
> -
> return strdup(dev_name);
> }
> }
> -
> - free(pent);
> -
> -out_close_dir:
> - closedir(sysdir);
> + return NULL;
This return and the hunk below are the one bit that I didn't have in my
patch; it's unreachable on the other branch, so you're entirely right to
move it!
> #else
> struct stat sbuf;
> char buf[PATH_MAX + 1];
> @@ -2914,7 +2899,6 @@ out_close_dir:
>
> return strdup(buf);
> #endif
> - return NULL;
> }
>
> char *drmGetPrimaryDeviceNameFromFd(int fd)
> --
> 2.16.0
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH libdrm v2] libdrm: Use readdir instead of readdir_r to avoid build warnings
2018-03-20 18:17 ` Eric Engestrom
@ 2018-03-22 16:51 ` Emil Velikov
2018-03-26 23:31 ` John Stultz
0 siblings, 1 reply; 4+ messages in thread
From: Emil Velikov @ 2018-03-22 16:51 UTC (permalink / raw)
To: Eric Engestrom; +Cc: Robert Foss, ML dri-devel, Stefan Schake
On 20 March 2018 at 18:17, Eric Engestrom <eric.engestrom@imgtec.com> wrote:
> On Tuesday, 2018-03-20 17:48:23 +0000, Emil Velikov wrote:
>> From: John Stultz <john.stultz@linaro.org>
>>
>> Building libdrm under AOSP, we see the following build warning:
>> external/libdrm/xf86drm.c:2861:12: warning: 'readdir_r' is deprecated: readdir_r is deprecated; use readdir instead [-Wdeprecated-declarations]
>> while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
>> ^
>>
>> Building on Linux with glibc produces the same warning.
>> Thus, this patch replaces readdir_r with readdir.
>>
>> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102031
>> Cc: Robert Foss <robert.foss@collabora.com>
>> Cc: Rob Herring <robh@kernel.org>
>> Cc: Stefan Schake <stschake@gmail.com>
>> Cc: John Stultz <john.stultz@linaro.org>
>> Cc: Eric Engestrom <eric.engestrom@imgtec.com>
>> Signed-off-by: John Stultz <john.stultz@linaro.org>
>> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
>> [Emil Velikov: remove unused variables, Eric]
>> Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
>
> I think that's pretty much exactly the patch I have at home :)
> (and that I forgot to send out last night)
>
> Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
>
Thanks pushed to master.
-Emil
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH libdrm v2] libdrm: Use readdir instead of readdir_r to avoid build warnings
2018-03-22 16:51 ` Emil Velikov
@ 2018-03-26 23:31 ` John Stultz
0 siblings, 0 replies; 4+ messages in thread
From: John Stultz @ 2018-03-26 23:31 UTC (permalink / raw)
To: Emil Velikov; +Cc: Robert Foss, ML dri-devel, Stefan Schake
On Thu, Mar 22, 2018 at 9:51 AM, Emil Velikov <emil.l.velikov@gmail.com> wrote:
> On 20 March 2018 at 18:17, Eric Engestrom <eric.engestrom@imgtec.com> wrote:
>> On Tuesday, 2018-03-20 17:48:23 +0000, Emil Velikov wrote:
>>> From: John Stultz <john.stultz@linaro.org>
>>>
>>> Building libdrm under AOSP, we see the following build warning:
>>> external/libdrm/xf86drm.c:2861:12: warning: 'readdir_r' is deprecated: readdir_r is deprecated; use readdir instead [-Wdeprecated-declarations]
>>> while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
>>> ^
>>>
>>> Building on Linux with glibc produces the same warning.
>>> Thus, this patch replaces readdir_r with readdir.
>>>
>>> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102031
>>> Cc: Robert Foss <robert.foss@collabora.com>
>>> Cc: Rob Herring <robh@kernel.org>
>>> Cc: Stefan Schake <stschake@gmail.com>
>>> Cc: John Stultz <john.stultz@linaro.org>
>>> Cc: Eric Engestrom <eric.engestrom@imgtec.com>
>>> Signed-off-by: John Stultz <john.stultz@linaro.org>
>>> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
>>> [Emil Velikov: remove unused variables, Eric]
>>> Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
>>
>> I think that's pretty much exactly the patch I have at home :)
>> (and that I forgot to send out last night)
>>
>> Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
>>
> Thanks pushed to master.
Sorry again for the slow response here, but an after-the-fact thanks
for sending out the much improved version!
I really appreciate it!
-john
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-03-26 23:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-20 17:48 [PATCH libdrm v2] libdrm: Use readdir instead of readdir_r to avoid build warnings Emil Velikov
2018-03-20 18:17 ` Eric Engestrom
2018-03-22 16:51 ` Emil Velikov
2018-03-26 23:31 ` John Stultz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).