public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Petri Latvala <petri.latvala@intel.com>
To: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
Cc: igt-dev@lists.freedesktop.org, Jani Nikula <jani.nikula@intel.com>
Subject: Re: [igt-dev] [PATCH i-g-t 6/8] igt/params: use igt_params_set_save for igt_set_module_param*
Date: Tue, 28 Apr 2020 15:54:27 +0300	[thread overview]
Message-ID: <20200428125427.GT9497@platvala-desk.ger.corp.intel.com> (raw)
In-Reply-To: <20200421161725.12249-7-juhapekka.heikkila@gmail.com>

On Tue, Apr 21, 2020 at 07:17:23PM +0300, Juha-Pekka Heikkila wrote:
> Unify parameter access.
> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
> ---
>  lib/igt_params.c | 133 +++++++++++++++++++++++++++++++++++------------
>  1 file changed, 100 insertions(+), 33 deletions(-)
> 
> diff --git a/lib/igt_params.c b/lib/igt_params.c
> index 8de47b02..369d224c 100644
> --- a/lib/igt_params.c
> +++ b/lib/igt_params.c
> @@ -27,12 +27,14 @@
>  #include <stdbool.h>
>  #include <stdio.h>
>  #include <sys/ioctl.h>
> +#include <sys/stat.h>
>  
>  #include <i915_drm.h>
>  
>  #include "igt_core.h"
>  #include "igt_params.h"
>  #include "igt_sysfs.h"
> +#include "igt_debugfs.h"
>  
>  struct module_param_data {
>  	char *path;
> @@ -107,15 +109,59 @@ static void igt_params_save(int dir, const char *path, const char *name)
>  	module_params = data;
>  }
>  
> -static int __igt_params_open(int device, char **outpath)
> +static int __igt_params_open(int device, char **outpath, const char *param)
>  {
>  	int dir, params = -1;
> +	struct stat buffer;
> +	char searchname[64];
> +	char searchpath[PATH_MAX];
> +	char *foundname, *ctx;
>  
> -	dir = igt_sysfs_open(device);
> +	dir = igt_debugfs_dir(device);
>  	if (dir >= 0) {
> -		params = openat(dir,
> -				"device/driver/module/parameters",
> -				O_RDONLY);
> +		int devname;
> +
> +		devname = openat(dir, "name", O_RDONLY);
> +		igt_assert(devname >= 0);
> +
> +		read(devname, searchname, sizeof(searchname));
> +		close(devname);
> +
> +		foundname = strtok_r(searchname, " ", &ctx);
> +		igt_assert(foundname);
> +
> +		snprintf(searchpath, PATH_MAX, "%s_params", foundname);
> +		params = openat(dir, searchpath, O_RDONLY);
> +
> +		if (params >= 0) {
> +			char *debugfspath = malloc(PATH_MAX);
> +
> +			igt_debugfs_path(device, debugfspath, PATH_MAX);
> +			if (param != NULL) {
> +				char filepath[PATH_MAX];
> +
> +				snprintf(filepath, PATH_MAX, "%s/%s",
> +					 debugfspath, param);
> +
> +				if (stat(filepath, &buffer) == 0) {
> +					if (outpath != NULL)
> +						*outpath = debugfspath;
> +					else
> +						free(debugfspath);
> +				} else {
> +					free(debugfspath);
> +					close(params);
> +					params = -1;
> +				}
> +			} else if (outpath != NULL) {
> +				/*
> +				 * Caller is responsible to free this.
> +				 */
> +				*outpath = debugfspath;
> +			} else {
> +				free(debugfspath);
> +			}
> +		}
>  		close(dir);
>  	}
>  
> @@ -124,11 +170,51 @@ static int __igt_params_open(int device, char **outpath)
>  		char name[32] = "";
>  		char path[PATH_MAX];
>  
> -		memset(&version, 0, sizeof(version));
> -		version.name_len = sizeof(name);
> -		version.name = name;
> -		ioctl(device, DRM_IOCTL_VERSION, &version);
> -
> +		if (device == -1) {
> +			/*
> +			 * find default device
> +			 */

Oh, here's the defaulting.

Like stated in the replies for one of the other patches, I'm not
greatly fond of carrying around a concept of a "default" device. Are
there users of -1 today?

This is also considerably more code that one would expect from just
"use params_set_save" as the subject states.




> +			int file, i;
> +			const char *debugfs_root = igt_debugfs_mount();
> +
> +			igt_assert(debugfs_root);
> +
> +			for (i = 0; i < 63; i++) {
> +				char testpath[PATH_MAX];
> +
> +				snprintf(searchpath, PATH_MAX,
> +					 "%s/dri/%d/name", debugfs_root, i);
> +
> +				file = open(searchpath, O_RDONLY);
> +
> +				if (file < 0)
> +					continue;
> +
> +				read(file, searchname, sizeof(searchname));
> +				close(file);
> +
> +				foundname = strtok_r(searchname, " ", &ctx);
> +				if (!foundname)
> +					continue;
> +
> +				snprintf(testpath, PATH_MAX,
> +					 "/sys/module/%s/parameters",
> +					 foundname);
> +
> +				if (stat(testpath, &buffer) == 0 &&
> +				    S_ISDIR(buffer.st_mode)) {
> +					memcpy(name, foundname,
> +					       (sizeof(name) < strlen(foundname) ?
> +					       sizeof(name) : strlen(foundname)));

If foundname is larger than the array, doesn't this leave 'name'
without a nul-termination?

-- 
Petri Latvala
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2020-04-28 12:54 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-21 16:17 [igt-dev] [PATCH i-g-t 0/8] Use device dependant module parameters Juha-Pekka Heikkila
2020-04-21 16:17 ` [igt-dev] [PATCH i-g-t 1/8] lib/params: add igt_params.c for module parameter access Juha-Pekka Heikkila
2020-04-22  8:02   ` Petri Latvala
2020-04-22  8:13     ` Juha-Pekka Heikkila
2020-04-22  8:19       ` Petri Latvala
2020-04-21 16:17 ` [igt-dev] [PATCH i-g-t 2/8] lib/params: start renaming functions igt_params_* Juha-Pekka Heikkila
2020-04-22  8:28   ` Petri Latvala
2020-04-22  8:34     ` Jani Nikula
2020-04-22  8:43       ` Petri Latvala
2020-04-22  8:48         ` Jani Nikula
2020-04-22  9:04           ` Arkadiusz Hiler
2020-04-21 16:17 ` [igt-dev] [PATCH i-g-t 3/8] lib/params: overhaul param saving Juha-Pekka Heikkila
2020-04-28 12:26   ` Petri Latvala
2020-04-28 18:40     ` Juha-Pekka Heikkila
2020-04-28 19:29       ` Juha-Pekka Heikkila
2020-04-21 16:17 ` [igt-dev] [PATCH i-g-t 4/8] params open with path return Juha-Pekka Heikkila
2020-04-28 12:31   ` Petri Latvala
2020-04-21 16:17 ` [igt-dev] [PATCH i-g-t 5/8] igt/params: add generic saving module parameter set Juha-Pekka Heikkila
2020-04-28 12:40   ` Petri Latvala
2020-04-28 18:43     ` Juha-Pekka Heikkila
2020-04-21 16:17 ` [igt-dev] [PATCH i-g-t 6/8] igt/params: use igt_params_set_save for igt_set_module_param* Juha-Pekka Heikkila
2020-04-28 12:54   ` Petri Latvala [this message]
2020-04-28 19:04     ` Juha-Pekka Heikkila
2020-04-21 16:17 ` [igt-dev] [PATCH i-g-t 7/8] lib/debugfs: use regular module param functions for prefault_disable Juha-Pekka Heikkila
2020-04-21 18:10   ` Chris Wilson
2020-04-21 18:30     ` Juha-Pekka Heikkila
2020-04-21 18:36       ` Chris Wilson
2020-04-21 18:59         ` Juha-Pekka Heikkila
2020-04-22  6:13           ` Jani Nikula
2020-04-21 16:17 ` [igt-dev] [PATCH i-g-t 8/8] tests/gem_eio: switch to using igt_params_set() Juha-Pekka Heikkila
2020-04-21 17:02 ` [igt-dev] ✗ Fi.CI.BAT: failure for Use device dependant module parameters (rev3) Patchwork
2020-04-21 18:08 ` [igt-dev] ✓ Fi.CI.BAT: success for Use device dependant module parameters (rev4) Patchwork
2020-04-22  1:05 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2020-04-20 12:17 [igt-dev] [PATCH i-g-t 0/8] Use device dependant module parameters Juha-Pekka Heikkila
2020-04-20 12:17 ` [igt-dev] [PATCH i-g-t 6/8] igt/params: use igt_params_set_save for igt_set_module_param* Juha-Pekka Heikkila
2020-04-19 15:17 [igt-dev] [PATCH i-g-t 0/8] Use device dependant module parameters Juha-Pekka Heikkila
2020-04-19 15:17 ` [igt-dev] [PATCH i-g-t 6/8] igt/params: use igt_params_set_save for igt_set_module_param* Juha-Pekka Heikkila

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=20200428125427.GT9497@platvala-desk.ger.corp.intel.com \
    --to=petri.latvala@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=jani.nikula@intel.com \
    --cc=juhapekka.heikkila@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