[Intel-gfx] [PATCH igt v3] lib: Add simple sysfs accessors

Ville Syrjälä ville.syrjala at linux.intel.com
Mon May 30 14:45:16 UTC 2016


On Fri, May 27, 2016 at 07:07:27PM +0100, Chris Wilson wrote:
> On Fri, May 27, 2016 at 08:46:14PM +0300, Ville Syrjälä wrote:
> > > +	for (int n = 0; n < 16; n++) {
> > > +		int len = sprintf(path, "/sys/class/drm/card%d", n);
> > > +		if (device[0]) {
> > > +			char tmp[80];
> > > +			int ret;
> > > +
> > > +			sprintf(path + len, "/dev");
> > > +			fd = open(path, O_RDONLY);
> > > +			if (fd == -1)
> > > +				continue;
> > > +
> > > +			ret = read(fd, tmp, sizeof(tmp-1));
> > > +			if (ret < 0)
> > > +				ret = 0;
> > > +			tmp[ret] = '\0';
> > > +			while (ret > 0 && tmp[ret-1] == '\n')
> > > +				tmp[--ret] = '\0';
> > > +			close(fd);
> > > +
> > > +			if (strcmp(tmp, device))
> > > +				continue;
> > 
> > fscanf?
> 
>                 if (fd != -1) {
>                         FILE *file;
>                         int ret, maj, min;
> 
>                         sprintf(path + len, "/dev");
>                         file = fopen(path, "r");
>                         if (!file)
>                                 continue;
> 
>                         ret = fscanf(file, "%d:%d", &maj, &min);
>                         fclose(file);
> 
>                         if (ret != 2 ||
>                             major(st.st_rdev) != maj ||
>                             minor(st.st_rdev) != min)
>                                 continue;

lgtm

-- 
Ville Syrjälä
Intel OTC


More information about the Intel-gfx mailing list