From: Eric Engestrom <eric.engestrom@intel.com>
To: Emil Velikov <emil.l.velikov@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH libdrm 1/2] xf86drm: fallback to MODALIAS for OF less platform devices
Date: Wed, 23 Jan 2019 11:04:24 +0000 [thread overview]
Message-ID: <20190123110424.pted67xfp6nlw7qz@intel.com> (raw)
In-Reply-To: <20190123104518.7332-1-emil.l.velikov@gmail.com>
On Wednesday, 2019-01-23 10:45:17 +0000, Emil Velikov wrote:
> From: Emil Velikov <emil.velikov@collabora.com>
>
> Some devices can lack OF data or it may not be available in the uevent
> file. Fallback to the MODALIAS data in those cases.
>
> We strip any leading "MODALIAS=.*:" thus the resulting information is
> compatible with existing code in Mesa.
>
> Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
> ---
> xf86drm.c | 55 ++++++++++++++++++++++++++++++++++++++++++-------------
> 1 file changed, 42 insertions(+), 13 deletions(-)
>
> diff --git a/xf86drm.c b/xf86drm.c
> index 10df682b..374734eb 100644
> --- a/xf86drm.c
> +++ b/xf86drm.c
> @@ -3511,15 +3511,28 @@ free_device:
> static int drmParsePlatformBusInfo(int maj, int min, drmPlatformBusInfoPtr info)
> {
> #ifdef __linux__
> - char path[PATH_MAX + 1], *name;
> + char path[PATH_MAX + 1], *name, *foo;
I assume you didn't mean to send this patch yet? :P
>
> snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device", maj, min);
>
> name = sysfs_uevent_get(path, "OF_FULLNAME");
> - if (!name)
> - return -ENOENT;
> + foo = name;
> + if (!name) {
> + /* If the device lacks OF data, pick the MODALIAS info */
> + name = sysfs_uevent_get(path, "MODALIAS");
> + if (!name)
> + return -ENOENT;
> +
> + /* .. and strip the MODALIAS=[platform,usb...]: part. */
> + foo = strrchr(name, ':');
> + if (!foo) {
> + free(name);
> + return -ENOENT;
> + }
> + foo++;
> + }
>
> - strncpy(info->fullname, name, DRM_PLATFORM_DEVICE_NAME_LEN);
> + strncpy(info->fullname, foo, DRM_PLATFORM_DEVICE_NAME_LEN);
> info->fullname[DRM_PLATFORM_DEVICE_NAME_LEN - 1] = '\0';
> free(name);
>
> @@ -3534,18 +3547,20 @@ static int drmParsePlatformDeviceInfo(int maj, int min,
> drmPlatformDeviceInfoPtr info)
> {
> #ifdef __linux__
> - char path[PATH_MAX + 1], *value;
> + char path[PATH_MAX + 1], *value, *foo;
> unsigned int count, i;
> int err;
>
> snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device", maj, min);
>
> value = sysfs_uevent_get(path, "OF_COMPATIBLE_N");
> - if (!value)
> - return -ENOENT;
> -
> - sscanf(value, "%u", &count);
> - free(value);
> + if (value) {
> + sscanf(value, "%u", &count);
> + free(value);
> + } else {
> + /* Assume one entry if the device lack OF data */
> + count = 1;
> + }
>
> info->compatible = calloc(count + 1, sizeof(*info->compatible));
> if (!info->compatible)
> @@ -3553,12 +3568,26 @@ static int drmParsePlatformDeviceInfo(int maj, int min,
>
> for (i = 0; i < count; i++) {
> value = sysfs_uevent_get(path, "OF_COMPATIBLE_%u", i);
> + foo = value;
> if (!value) {
> - err = -ENOENT;
> - goto free;
> + /* If the device lacks OF data, pick the MODALIAS info */
> + value = sysfs_uevent_get(path, "MODALIAS");
> + if (!value) {
> + err = -ENOENT;
> + goto free;
> + }
> +
> + /* .. and strip the MODALIAS=[platform,usb...]: part. */
> + foo = strrchr(value, ':');
> + if (!foo) {
> + free(value);
> + return -ENOENT;
> + }
> + foo = strdup(foo + 1);
> + free(value);
> }
>
> - info->compatible[i] = value;
> + info->compatible[i] = foo;
> }
>
> return 0;
> --
> 2.20.1
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2019-01-23 11:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-23 10:45 [PATCH libdrm 1/2] xf86drm: fallback to MODALIAS for OF less platform devices Emil Velikov
2019-01-23 10:45 ` [PATCH libdrm 2/2] xf85drm: de-duplicate drmParse{Platform.Host1x}{Bus, Device}Info Emil Velikov
2019-01-25 13:11 ` Eric Engestrom
2019-01-23 11:04 ` Eric Engestrom [this message]
2019-01-23 11:26 ` [PATCH libdrm 1/2] xf86drm: fallback to MODALIAS for OF less platform devices Emil Velikov
2019-01-24 14:42 ` Emil Velikov
2019-02-01 14:15 ` Lucas Stach
2019-02-04 15:39 ` Emil Velikov
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=20190123110424.pted67xfp6nlw7qz@intel.com \
--to=eric.engestrom@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=emil.l.velikov@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox