diff mbox series

[v3,4/4] libpdbg: Improve the logic to check if fdt is writable

Message ID 20200304031913.150094-5-amitay@ozlabs.org
State Accepted
Headers show
Series Fix handling of attributes for virtual targets | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch warning Failed to apply on branch master (8b4611b5d8e7e2279fe4aa80c892fcfe10aa398d)
snowpatch_ozlabs/apply_patch fail Failed to apply to any branch
snowpatch_ozlabs/apply_patch warning Failed to apply on branch master (029483b62a5bb7acbbc4c5d9aa2d81bf79431e26)
snowpatch_ozlabs/apply_patch fail Failed to apply to any branch

Commit Message

Amitay Isaacs March 4, 2020, 3:19 a.m. UTC
Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 libpdbg/device.c |  2 +-
 libpdbg/dtb.c    | 24 +++++++++---------------
 libpdbg/target.h |  3 ++-
 3 files changed, 12 insertions(+), 17 deletions(-)

Comments

Alistair Popple March 4, 2020, 3:35 a.m. UTC | #1
Reviewed-by: Alistair Popple <alistair@popple.id.au>

On Wednesday, 4 March 2020 2:19:13 PM AEDT Amitay Isaacs wrote:
> Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
> ---
>  libpdbg/device.c |  2 +-
>  libpdbg/dtb.c    | 24 +++++++++---------------
>  libpdbg/target.h |  3 ++-
>  3 files changed, 12 insertions(+), 17 deletions(-)
> 
> diff --git a/libpdbg/device.c b/libpdbg/device.c
> index cd8a459..604cddb 100644
> --- a/libpdbg/device.c
> +++ b/libpdbg/device.c
> @@ -355,7 +355,7 @@ bool pdbg_target_set_property(struct pdbg_target
> *target, const char *name, cons if (!p)
>  		return false;
> 
> -	if (!target->fdt || !pdbg_fdt_is_writeable(target->fdt))
> +	if (!target->fdt || pdbg_fdt_is_readonly(target->fdt))
>  		return false;
> 
>  	if (len != size)
> diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c
> index 57502c1..35923b0 100644
> --- a/libpdbg/dtb.c
> +++ b/libpdbg/dtb.c
> @@ -63,10 +63,12 @@ static struct pdbg_dtb pdbg_dtb = {
>  	.backend = {
>  		.fd = -1,
>  		.len = -1,
> +		.readonly = true,
>  	},
>  	.system = {
>  		.fd = -1,
>  		.len = -1,
> +		.readonly = true,
>  	},
>  };
> 
> @@ -270,6 +272,7 @@ static void mmap_dtb(char *file, bool readonly, struct
> pdbg_mfile *mfile) .fd = fd,
>  		.len = statbuf.st_size,
>  		.fdt = dtb,
> +		.readonly = readonly,
>  	};
>  	return;
> 
> @@ -408,24 +411,15 @@ done:
>  	return dtb;
>  }
> 
> -static bool is_fdt_mapped(void *fdt, struct pdbg_mfile *mfile)
> +bool pdbg_fdt_is_readonly(void *fdt)
>  {
> -	if (mfile->fdt == fdt && mfile->fd != -1 && mfile->len != -1) {
> -		return true;
> -	}
> -
> -	return false;
> -}
> +	if (pdbg_dtb.system.fdt == fdt)
> +		return pdbg_dtb.system.readonly;
> 
> -bool pdbg_fdt_is_writeable(void *fdt)
> -{
> -	bool ok;
> -
> -	ok = is_fdt_mapped(fdt, &pdbg_dtb.system);
> -	if (!ok)
> -		ok = is_fdt_mapped(fdt, &pdbg_dtb.backend);
> +	if (pdbg_dtb.backend.fdt == fdt)
> +		return pdbg_dtb.backend.readonly;
> 
> -	return ok;
> +	return true;
>  }
> 
>  static void close_dtb(struct pdbg_mfile *mfile)
> diff --git a/libpdbg/target.h b/libpdbg/target.h
> index fffdc49..3b74844 100644
> --- a/libpdbg/target.h
> +++ b/libpdbg/target.h
> @@ -60,6 +60,7 @@ struct pdbg_mfile {
>  	int fd;
>  	ssize_t len;
>  	void *fdt;
> +	bool readonly;
>  };
> 
>  struct pdbg_dtb {
> @@ -80,7 +81,7 @@ extern struct list_head target_classes;
> 
>  struct pdbg_dtb *pdbg_default_dtb(void *system_fdt);
>  const char *pdbg_get_backend_option(void);
> -bool pdbg_fdt_is_writeable(void *fdt);
> +bool pdbg_fdt_is_readonly(void *fdt);
> 
>  struct chipop *pib_to_chipop(struct pdbg_target *target);
>  bool target_is_virtual(struct pdbg_target *target);
diff mbox series

Patch

diff --git a/libpdbg/device.c b/libpdbg/device.c
index cd8a459..604cddb 100644
--- a/libpdbg/device.c
+++ b/libpdbg/device.c
@@ -355,7 +355,7 @@  bool pdbg_target_set_property(struct pdbg_target *target, const char *name, cons
 	if (!p)
 		return false;
 
-	if (!target->fdt || !pdbg_fdt_is_writeable(target->fdt))
+	if (!target->fdt || pdbg_fdt_is_readonly(target->fdt))
 		return false;
 
 	if (len != size)
diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c
index 57502c1..35923b0 100644
--- a/libpdbg/dtb.c
+++ b/libpdbg/dtb.c
@@ -63,10 +63,12 @@  static struct pdbg_dtb pdbg_dtb = {
 	.backend = {
 		.fd = -1,
 		.len = -1,
+		.readonly = true,
 	},
 	.system = {
 		.fd = -1,
 		.len = -1,
+		.readonly = true,
 	},
 };
 
@@ -270,6 +272,7 @@  static void mmap_dtb(char *file, bool readonly, struct pdbg_mfile *mfile)
 		.fd = fd,
 		.len = statbuf.st_size,
 		.fdt = dtb,
+		.readonly = readonly,
 	};
 	return;
 
@@ -408,24 +411,15 @@  done:
 	return dtb;
 }
 
-static bool is_fdt_mapped(void *fdt, struct pdbg_mfile *mfile)
+bool pdbg_fdt_is_readonly(void *fdt)
 {
-	if (mfile->fdt == fdt && mfile->fd != -1 && mfile->len != -1) {
-		return true;
-	}
-
-	return false;
-}
+	if (pdbg_dtb.system.fdt == fdt)
+		return pdbg_dtb.system.readonly;
 
-bool pdbg_fdt_is_writeable(void *fdt)
-{
-	bool ok;
-
-	ok = is_fdt_mapped(fdt, &pdbg_dtb.system);
-	if (!ok)
-		ok = is_fdt_mapped(fdt, &pdbg_dtb.backend);
+	if (pdbg_dtb.backend.fdt == fdt)
+		return pdbg_dtb.backend.readonly;
 
-	return ok;
+	return true;
 }
 
 static void close_dtb(struct pdbg_mfile *mfile)
diff --git a/libpdbg/target.h b/libpdbg/target.h
index fffdc49..3b74844 100644
--- a/libpdbg/target.h
+++ b/libpdbg/target.h
@@ -60,6 +60,7 @@  struct pdbg_mfile {
 	int fd;
 	ssize_t len;
 	void *fdt;
+	bool readonly;
 };
 
 struct pdbg_dtb {
@@ -80,7 +81,7 @@  extern struct list_head target_classes;
 
 struct pdbg_dtb *pdbg_default_dtb(void *system_fdt);
 const char *pdbg_get_backend_option(void);
-bool pdbg_fdt_is_writeable(void *fdt);
+bool pdbg_fdt_is_readonly(void *fdt);
 
 struct chipop *pib_to_chipop(struct pdbg_target *target);
 bool target_is_virtual(struct pdbg_target *target);