diff mbox series

[i-g-t,v4,4/5] lib/gem_engine_topology: Simplify the method of opening a primary

Message ID 20240718085912.15434-11-janusz.krzysztofik@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series tests/gem_ctx_exec: Fix failing preempt timeout updates | expand

Commit Message

Janusz Krzysztofik July 18, 2024, 8:55 a.m. UTC
When opening a potential primary counterpart of a render device, we first
open a parent directory of the render node and pass it to openat() that
can open a path relative to that directory.  But on the other hand, we
build and pass to that function a path of that primary that is absolute,
not relative.  While that construct gives the expected result anyway, it
makes the picture unclear.

Use open() and drop unused code.

Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
---
 lib/i915/gem_engine_topology.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

Comments

Kamil Konieczny July 18, 2024, 12:14 p.m. UTC | #1
Hi Janusz,
On 2024-07-18 at 10:55:15 +0200, Janusz Krzysztofik wrote:
> When opening a potential primary counterpart of a render device, we first
> open a parent directory of the render node and pass it to openat() that
> can open a path relative to that directory.  But on the other hand, we
> build and pass to that function a path of that primary that is absolute,
> not relative.  While that construct gives the expected result anyway, it
> makes the picture unclear.
> 
> Use open() and drop unused code.
> 
> Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>

Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>


> ---
>  lib/i915/gem_engine_topology.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/lib/i915/gem_engine_topology.c b/lib/i915/gem_engine_topology.c
> index 8589af5c1a..c8c1079223 100644
> --- a/lib/i915/gem_engine_topology.c
> +++ b/lib/i915/gem_engine_topology.c
> @@ -470,14 +470,10 @@ static int __open_primary(int dir)
>  	if (igt_debug_on(readlinkat(dir, "device", target, sizeof(target)) < 0))
>  		return dir;
>  
> -	fd = openat(dir, "..", O_RDONLY);
> -	if (fd < 0)
> -		return dir;
> -
>  	close(dir);
>  	for (minor = 0; minor < 64; minor++) {
>  		sprintf(buf, "/sys/dev/char/%d:%d", major, minor);
> -		dir = openat(fd, buf, O_RDONLY);
> +		dir = open(buf, O_RDONLY);
>  		if (dir < 0)
>  			continue;
>  
> @@ -488,7 +484,6 @@ static int __open_primary(int dir)
>  		close(dir);
>  		dir = -1;
>  	}
> -	close(fd);
>  
>  	return dir;
>  }
> -- 
> 2.45.2
>
diff mbox series

Patch

diff --git a/lib/i915/gem_engine_topology.c b/lib/i915/gem_engine_topology.c
index 8589af5c1a..c8c1079223 100644
--- a/lib/i915/gem_engine_topology.c
+++ b/lib/i915/gem_engine_topology.c
@@ -470,14 +470,10 @@  static int __open_primary(int dir)
 	if (igt_debug_on(readlinkat(dir, "device", target, sizeof(target)) < 0))
 		return dir;
 
-	fd = openat(dir, "..", O_RDONLY);
-	if (fd < 0)
-		return dir;
-
 	close(dir);
 	for (minor = 0; minor < 64; minor++) {
 		sprintf(buf, "/sys/dev/char/%d:%d", major, minor);
-		dir = openat(fd, buf, O_RDONLY);
+		dir = open(buf, O_RDONLY);
 		if (dir < 0)
 			continue;
 
@@ -488,7 +484,6 @@  static int __open_primary(int dir)
 		close(dir);
 		dir = -1;
 	}
-	close(fd);
 
 	return dir;
 }