From: Robert Foss <robert.foss@collabora.com>
To: Emil Velikov <emil.l.velikov@gmail.com>, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH libdrm 03/10] xf86drm: Fold drmDevice processing into process_device() helper
Date: Thu, 28 Jun 2018 13:50:48 +0200 [thread overview]
Message-ID: <643f4626-20fd-8801-e266-3e27ff18704e@collabora.com> (raw)
In-Reply-To: <20180625173626.8046-3-emil.l.velikov@gmail.com>
Feel free to add my r-b to this patch.
On 2018-06-25 19:36, Emil Velikov wrote:
> From: Emil Velikov <emil.velikov@collabora.com>
>
> Don't the duplicate (nearly) identical code across the two call sites.
> It improves legibility and the diff stat seems nice.
>
> Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
> ---
> xf86drm.c | 159 ++++++++++++++++++------------------------------------
> 1 file changed, 51 insertions(+), 108 deletions(-)
>
> diff --git a/xf86drm.c b/xf86drm.c
> index cbc0a408..114cf855 100644
> --- a/xf86drm.c
> +++ b/xf86drm.c
> @@ -3676,6 +3676,52 @@ free_device:
> return ret;
> }
>
> +static int
> +process_device(drmDevicePtr *device, const char *d_name,
> + int req_subsystem_type,
> + bool fetch_deviceinfo, uint32_t flags)
> +{
> + struct stat sbuf;
> + char node[PATH_MAX + 1];
> + int node_type, subsystem_type;
> + unsigned int maj, min;
> +
> + node_type = drmGetNodeType(d_name);
> + if (node_type < 0)
> + return -1;
> +
> + snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, d_name);
> + if (stat(node, &sbuf))
> + return -1;
> +
> + maj = major(sbuf.st_rdev);
> + min = minor(sbuf.st_rdev);
> +
> + if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
> + return -1;
> +
> + subsystem_type = drmParseSubsystemType(maj, min);
> + if (req_subsystem_type != -1 && req_subsystem_type != subsystem_type)
> + return -1;
> +
> + switch (subsystem_type) {
> + case DRM_BUS_PCI:
> + return drmProcessPciDevice(device, node, node_type, maj, min,
> + fetch_deviceinfo, flags);
> + case DRM_BUS_USB:
> + return drmProcessUsbDevice(device, node, node_type, maj, min,
> + fetch_deviceinfo, flags);
> + case DRM_BUS_PLATFORM:
> + return drmProcessPlatformDevice(device, node, node_type, maj, min,
> + fetch_deviceinfo, flags);
> + case DRM_BUS_HOST1X:
> + return drmProcessHost1xDevice(device, node, node_type, maj, min,
> + fetch_deviceinfo, flags);
> + default:
> + return -1;
> + }
> +}
> +
> /* Consider devices located on the same bus as duplicate and fold the respective
> * entries into a single one.
> *
> @@ -3805,8 +3851,7 @@ int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
> DIR *sysdir;
> struct dirent *dent;
> struct stat sbuf;
> - char node[PATH_MAX + 1];
> - int node_type, subsystem_type;
> + int subsystem_type;
> int maj, min;
> int ret, i, node_count;
> int max_count = 16;
> @@ -3844,55 +3889,9 @@ int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
>
> i = 0;
> while ((dent = readdir(sysdir))) {
> - node_type = drmGetNodeType(dent->d_name);
> - if (node_type < 0)
> - continue;
> -
> - snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, dent->d_name);
> - if (stat(node, &sbuf))
> - continue;
> -
> - maj = major(sbuf.st_rdev);
> - min = minor(sbuf.st_rdev);
> -
> - if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
> - continue;
> -
> - if (drmParseSubsystemType(maj, min) != subsystem_type)
> - continue;
> -
> - switch (subsystem_type) {
> - case DRM_BUS_PCI:
> - ret = drmProcessPciDevice(&d, node, node_type, maj, min, true, flags);
> - if (ret)
> - continue;
> -
> - break;
> -
> - case DRM_BUS_USB:
> - ret = drmProcessUsbDevice(&d, node, node_type, maj, min, true, flags);
> - if (ret)
> - continue;
> -
> - break;
> -
> - case DRM_BUS_PLATFORM:
> - ret = drmProcessPlatformDevice(&d, node, node_type, maj, min, true, flags);
> - if (ret)
> - continue;
> -
> - break;
> -
> - case DRM_BUS_HOST1X:
> - ret = drmProcessHost1xDevice(&d, node, node_type, maj, min, true, flags);
> - if (ret)
> - continue;
> -
> - break;
> -
> - default:
> + ret = process_device(&d, dent->d_name, subsystem_type, true, flags);
> + if (ret)
> continue;
> - }
>
> if (i >= max_count) {
> drmDevicePtr *temp;
> @@ -3973,10 +3972,6 @@ int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_devices)
> drmDevicePtr device;
> DIR *sysdir;
> struct dirent *dent;
> - struct stat sbuf;
> - char node[PATH_MAX + 1];
> - int node_type, subsystem_type;
> - int maj, min;
> int ret, i, node_count, device_count;
> int max_count = 16;
>
> @@ -3995,61 +3990,9 @@ int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_devices)
>
> i = 0;
> while ((dent = readdir(sysdir))) {
> - node_type = drmGetNodeType(dent->d_name);
> - if (node_type < 0)
> - continue;
> -
> - snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, dent->d_name);
> - if (stat(node, &sbuf))
> - continue;
> -
> - maj = major(sbuf.st_rdev);
> - min = minor(sbuf.st_rdev);
> -
> - if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
> - continue;
> -
> - subsystem_type = drmParseSubsystemType(maj, min);
> -
> - if (subsystem_type < 0)
> - continue;
> -
> - switch (subsystem_type) {
> - case DRM_BUS_PCI:
> - ret = drmProcessPciDevice(&device, node, node_type,
> - maj, min, devices != NULL, flags);
> - if (ret)
> - continue;
> -
> - break;
> -
> - case DRM_BUS_USB:
> - ret = drmProcessUsbDevice(&device, node, node_type, maj, min,
> - devices != NULL, flags);
> - if (ret)
> - continue;
> -
> - break;
> -
> - case DRM_BUS_PLATFORM:
> - ret = drmProcessPlatformDevice(&device, node, node_type, maj, min,
> - devices != NULL, flags);
> - if (ret)
> - continue;
> -
> - break;
> -
> - case DRM_BUS_HOST1X:
> - ret = drmProcessHost1xDevice(&device, node, node_type, maj, min,
> - devices != NULL, flags);
> - if (ret)
> - continue;
> -
> - break;
> -
> - default:
> + ret = process_device(&device, dent->d_name, -1, devices != NULL, flags);
> + if (ret)
> continue;
> - }
>
> if (i >= max_count) {
> drmDevicePtr *temp;
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2018-06-28 11:50 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-25 17:36 [PATCH libdrm 01/10] xf86drm: drmGetDevice2: error out if the fd has unknown subsys Emil Velikov
2018-06-25 17:36 ` [PATCH libdrm 02/10] xf86drm: introduce drm_device_has_rdev() helper Emil Velikov
2018-06-28 10:14 ` Robert Foss
2018-06-25 17:36 ` [PATCH libdrm 03/10] xf86drm: Fold drmDevice processing into process_device() helper Emil Velikov
2018-06-28 11:50 ` Robert Foss [this message]
2018-06-25 17:36 ` [PATCH libdrm 04/10] xf86drm: Allocate drmDevicePtr's on stack Emil Velikov
2018-06-28 12:52 ` Robert Foss
2018-06-28 17:07 ` Emil Velikov
2018-06-29 15:20 ` [PATCH libdrm v2 " Emil Velikov
2018-06-29 15:49 ` Robert Foss
2018-06-29 15:22 ` [PATCH libdrm v2 05/10] xf86drm: introduce a get_real_pci_path() helper Emil Velikov
2018-06-25 17:36 ` [PATCH libdrm " Emil Velikov
2018-06-28 10:21 ` Eric Engestrom
2018-06-28 10:23 ` Eric Engestrom
2018-06-28 16:42 ` Emil Velikov
2018-06-28 16:06 ` Robert Foss
2018-06-25 17:36 ` [PATCH libdrm 06/10] xf86drm: Add drmDevice support for virtio_gpu Emil Velikov
2018-06-28 16:08 ` Robert Foss
2018-06-25 17:36 ` [PATCH libdrm 07/10] tests/drmdevices: install alongside other utilities Emil Velikov
2018-06-28 16:09 ` Robert Foss
2018-06-25 17:36 ` [PATCH libdrm 08/10] tests/drmdevice: add a couple of printf headers Emil Velikov
2018-06-28 16:09 ` Robert Foss
2018-06-25 17:36 ` [PATCH libdrm 09/10] drmdevice: convert the tabbed output into a tree Emil Velikov
2018-06-28 10:19 ` Eric Engestrom
2018-06-28 16:43 ` Emil Velikov
2018-06-28 16:09 ` Robert Foss
2018-06-29 15:24 ` [PATCH libdrm v2 " Emil Velikov
2018-06-25 17:36 ` [PATCH libdrm 10/10] drmdevice: print the correct host1x information Emil Velikov
2018-06-28 16:09 ` Robert Foss
2018-06-28 10:11 ` [PATCH libdrm 01/10] xf86drm: drmGetDevice2: error out if the fd has unknown subsys Robert Foss
2018-06-28 10:11 ` Robert Foss
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=643f4626-20fd-8801-e266-3e27ff18704e@collabora.com \
--to=robert.foss@collabora.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;
as well as URLs for NNTP newsgroup(s).