All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] target/ppc/kvm: Skip current and parent directories in kvmppc_find_cpu_dt
@ 2022-07-12 21:08 Murilo Opsfelder Araujo
  2022-07-13  1:54 ` David Gibson
  2022-07-14 13:00 ` Daniel Henrique Barboza
  0 siblings, 2 replies; 3+ messages in thread
From: Murilo Opsfelder Araujo @ 2022-07-12 21:08 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc
  Cc: Paolo Bonzini, Greg Kurz, David Gibson, Daniel Henrique Barboza,
	Cédric Le Goater, mopsfelder, Murilo Opsfelder Araujo,
	Fabiano Rosas

Some systems have /proc/device-tree/cpus/../clock-frequency. However,
this is not the expected path for a CPU device tree directory.

Signed-off-by: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
---
v2:
- Skip current and parent directories.

v1: https://lore.kernel.org/qemu-devel/20220711193743.51456-1-muriloo@linux.ibm.com/

 target/ppc/kvm.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 6eed466f80..466d0d2f4c 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -1877,6 +1877,12 @@ static int kvmppc_find_cpu_dt(char *buf, int buf_len)
     buf[0] = '\0';
     while ((dirp = readdir(dp)) != NULL) {
         FILE *f;
+
+        /* Don't accidentally read from the current and parent directories */
+        if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) {
+            continue;
+        }
+
         snprintf(buf, buf_len, "%s%s/clock-frequency", PROC_DEVTREE_CPU,
                  dirp->d_name);
         f = fopen(buf, "r");
-- 
2.36.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] target/ppc/kvm: Skip current and parent directories in kvmppc_find_cpu_dt
  2022-07-12 21:08 [PATCH v2] target/ppc/kvm: Skip current and parent directories in kvmppc_find_cpu_dt Murilo Opsfelder Araujo
@ 2022-07-13  1:54 ` David Gibson
  2022-07-14 13:00 ` Daniel Henrique Barboza
  1 sibling, 0 replies; 3+ messages in thread
From: David Gibson @ 2022-07-13  1:54 UTC (permalink / raw)
  To: Murilo Opsfelder Araujo
  Cc: qemu-devel, qemu-ppc, Paolo Bonzini, Greg Kurz,
	Daniel Henrique Barboza, Cédric Le Goater, mopsfelder,
	Fabiano Rosas

[-- Attachment #1: Type: text/plain, Size: 1527 bytes --]

On Tue, Jul 12, 2022 at 06:08:10PM -0300, Murilo Opsfelder Araujo wrote:
> Some systems have /proc/device-tree/cpus/../clock-frequency. However,
> this is not the expected path for a CPU device tree directory.
> 
> Signed-off-by: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
> Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

and, I believe, mea culpa.

> ---
> v2:
> - Skip current and parent directories.
> 
> v1: https://lore.kernel.org/qemu-devel/20220711193743.51456-1-muriloo@linux.ibm.com/
> 
>  target/ppc/kvm.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> index 6eed466f80..466d0d2f4c 100644
> --- a/target/ppc/kvm.c
> +++ b/target/ppc/kvm.c
> @@ -1877,6 +1877,12 @@ static int kvmppc_find_cpu_dt(char *buf, int buf_len)
>      buf[0] = '\0';
>      while ((dirp = readdir(dp)) != NULL) {
>          FILE *f;
> +
> +        /* Don't accidentally read from the current and parent directories */
> +        if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) {
> +            continue;
> +        }
> +
>          snprintf(buf, buf_len, "%s%s/clock-frequency", PROC_DEVTREE_CPU,
>                   dirp->d_name);
>          f = fopen(buf, "r");

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] target/ppc/kvm: Skip current and parent directories in kvmppc_find_cpu_dt
  2022-07-12 21:08 [PATCH v2] target/ppc/kvm: Skip current and parent directories in kvmppc_find_cpu_dt Murilo Opsfelder Araujo
  2022-07-13  1:54 ` David Gibson
@ 2022-07-14 13:00 ` Daniel Henrique Barboza
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Henrique Barboza @ 2022-07-14 13:00 UTC (permalink / raw)
  To: Murilo Opsfelder Araujo, qemu-devel, qemu-ppc
  Cc: Paolo Bonzini, Greg Kurz, David Gibson, Cédric Le Goater,
	mopsfelder, Fabiano Rosas



On 7/12/22 18:08, Murilo Opsfelder Araujo wrote:
> Some systems have /proc/device-tree/cpus/../clock-frequency. However,
> this is not the expected path for a CPU device tree directory.
> 
> Signed-off-by: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
> Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
> ---

Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>


and queued.


Daniel

> v2:
> - Skip current and parent directories.
> 
> v1: https://lore.kernel.org/qemu-devel/20220711193743.51456-1-muriloo@linux.ibm.com/
> 
>   target/ppc/kvm.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> index 6eed466f80..466d0d2f4c 100644
> --- a/target/ppc/kvm.c
> +++ b/target/ppc/kvm.c
> @@ -1877,6 +1877,12 @@ static int kvmppc_find_cpu_dt(char *buf, int buf_len)
>       buf[0] = '\0';
>       while ((dirp = readdir(dp)) != NULL) {
>           FILE *f;
> +
> +        /* Don't accidentally read from the current and parent directories */
> +        if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) {
> +            continue;
> +        }
> +
>           snprintf(buf, buf_len, "%s%s/clock-frequency", PROC_DEVTREE_CPU,
>                    dirp->d_name);
>           f = fopen(buf, "r");


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-14 13:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-12 21:08 [PATCH v2] target/ppc/kvm: Skip current and parent directories in kvmppc_find_cpu_dt Murilo Opsfelder Araujo
2022-07-13  1:54 ` David Gibson
2022-07-14 13:00 ` Daniel Henrique Barboza

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.