From: Chris Wilson <chris@chris-wilson.co.uk> To: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>, intel-gfx@lists.freedesktop.org Cc: igt-dev@lists.freedesktop.org Subject: Re: [Intel-gfx] [igt-dev] [PATCH i-g-t v3] i915/perf: Find the associated perf-type for a particular device Date: Tue, 14 Jan 2020 10:15:25 +0000 [thread overview] Message-ID: <157899692591.27314.10652294075559860834@skylake-alporthouse-com> (raw) In-Reply-To: <06e82c0a-3752-6d30-0aa0-0bb9993b5bae@linux.intel.com> Quoting Tvrtko Ursulin (2020-01-14 10:09:15) > > On 10/01/2020 11:53, Chris Wilson wrote: > > -uint64_t i915_type_id(void) > > +static char *bus_address(int i915, char *path, int pathlen) > > +{ > > + struct stat st; > > + int len = -1; > > + int dir; > > + char *s; > > + > > + if (fstat(i915, &st) || !S_ISCHR(st.st_mode)) > > + return NULL; > > + > > + snprintf(path, pathlen, "/sys/dev/char/%d:%d", > > + major(st.st_rdev), minor(st.st_rdev)); > > + > > + dir = open(path, O_RDONLY); > > + if (dir != -1) { > > + len = readlinkat(dir, "device", path, pathlen - 1); > > + close(dir); > > + } > > + if (len < 0) > > + return NULL; > > + > > + path[len] = '\0'; > > In the realm of hypothetical but an assert that no truncation occurred > would be good. > > if (len == pathlen - 1) > return NULL; > > ? > > Although it is not clear to me from man readlinkat how do we distinguish > between truncation and exact fit. > > Or you were counting on failure at a later step if truncation occurred? I did not expect a partial match to ever succeed. We at least know for the moment the names are fixed. > Maybe try stat(2) in this wrapper to be sure function returns a valid path? That would have the same danger of a partial match. I think the foolproof solution here is having pmu_name in /sys/class/drm/cardN/pmu_name. (Or rather /sys/dev/char/%d:%d/device/pnu_name. :) -Chris _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx
WARNING: multiple messages have this Message-ID (diff)
From: Chris Wilson <chris@chris-wilson.co.uk> To: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>, intel-gfx@lists.freedesktop.org Cc: igt-dev@lists.freedesktop.org, Tvrtko Ursulin <tvrtko.ursulin@intel.com> Subject: Re: [igt-dev] [PATCH i-g-t v3] i915/perf: Find the associated perf-type for a particular device Date: Tue, 14 Jan 2020 10:15:25 +0000 [thread overview] Message-ID: <157899692591.27314.10652294075559860834@skylake-alporthouse-com> (raw) In-Reply-To: <06e82c0a-3752-6d30-0aa0-0bb9993b5bae@linux.intel.com> Quoting Tvrtko Ursulin (2020-01-14 10:09:15) > > On 10/01/2020 11:53, Chris Wilson wrote: > > -uint64_t i915_type_id(void) > > +static char *bus_address(int i915, char *path, int pathlen) > > +{ > > + struct stat st; > > + int len = -1; > > + int dir; > > + char *s; > > + > > + if (fstat(i915, &st) || !S_ISCHR(st.st_mode)) > > + return NULL; > > + > > + snprintf(path, pathlen, "/sys/dev/char/%d:%d", > > + major(st.st_rdev), minor(st.st_rdev)); > > + > > + dir = open(path, O_RDONLY); > > + if (dir != -1) { > > + len = readlinkat(dir, "device", path, pathlen - 1); > > + close(dir); > > + } > > + if (len < 0) > > + return NULL; > > + > > + path[len] = '\0'; > > In the realm of hypothetical but an assert that no truncation occurred > would be good. > > if (len == pathlen - 1) > return NULL; > > ? > > Although it is not clear to me from man readlinkat how do we distinguish > between truncation and exact fit. > > Or you were counting on failure at a later step if truncation occurred? I did not expect a partial match to ever succeed. We at least know for the moment the names are fixed. > Maybe try stat(2) in this wrapper to be sure function returns a valid path? That would have the same danger of a partial match. I think the foolproof solution here is having pmu_name in /sys/class/drm/cardN/pmu_name. (Or rather /sys/dev/char/%d:%d/device/pnu_name. :) -Chris _______________________________________________ igt-dev mailing list igt-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2020-01-14 10:15 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-01-10 11:53 [Intel-gfx] [PATCH i-g-t v3] i915/perf: Find the associated perf-type for a particular device Chris Wilson 2020-01-10 11:53 ` [igt-dev] " Chris Wilson 2020-01-10 14:08 ` [igt-dev] ✓ Fi.CI.BAT: success for i915/perf: Find the associated perf-type for a particular device (rev4) Patchwork 2020-01-13 21:41 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork 2020-01-14 10:09 ` [Intel-gfx] [igt-dev] [PATCH i-g-t v3] i915/perf: Find the associated perf-type for a particular device Tvrtko Ursulin 2020-01-14 10:09 ` Tvrtko Ursulin 2020-01-14 10:15 ` Chris Wilson [this message] 2020-01-14 10:15 ` Chris Wilson 2020-01-14 10:21 ` [Intel-gfx] " Tvrtko Ursulin 2020-01-14 10:21 ` Tvrtko Ursulin
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=157899692591.27314.10652294075559860834@skylake-alporthouse-com \ --to=chris@chris-wilson.co.uk \ --cc=igt-dev@lists.freedesktop.org \ --cc=intel-gfx@lists.freedesktop.org \ --cc=tvrtko.ursulin@linux.intel.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: linkBe 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.