All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kexec/fs2dt: Use slurp_file_len to avoid partial read of files
@ 2014-12-01 23:59 Anton Blanchard
  2014-12-02  1:51 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: Anton Blanchard @ 2014-12-01 23:59 UTC (permalink / raw)
  To: horms; +Cc: kexec

The OPAL firmware is going to embed its symbol map in the device tree.
The size is large enough to be more than a page, and it takes
multiple reads to get the whole file. This is because sysfs uses
the seq_file helpers which do a page at a time.

Unfortunately fs2dt has no handling for short reads and we die with:

unrecoverable error: short read from"/proc/device-tree//ibm,opal/firmware/symbol-map"

This patch uses the slurp_file_len helper which does the right thing.
It moves the explicit open of the file further down for
add_usable_mem_property and add_dyn_reconf_usable_mem_property.
We should convert both of these to use the buffer provided by
slurp_file_len at some stage.

Signed-off-by: Anton Blanchard <anton@samba.org>
---
 kexec/fs2dt.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/kexec/fs2dt.c b/kexec/fs2dt.c
index 304f6cb..3b4432d 100644
--- a/kexec/fs2dt.c
+++ b/kexec/fs2dt.c
@@ -381,8 +381,8 @@ static void putprops(char *fn, struct dirent **nlist, int numlist)
 {
 	struct dirent *dp;
 	int i = 0, fd;
-	size_t len;
-	ssize_t slen;
+	off_t len;
+	off_t slen;
 	struct stat statbuf;
 
 	for (i = 0; i < numlist; i++) {
@@ -443,23 +443,27 @@ static void putprops(char *fn, struct dirent **nlist, int numlist)
 		*dt++ = cpu_to_be32(propnum(fn));
 		pad_structure_block(len);
 
-		fd = open(pathname, O_RDONLY);
-		if (fd == -1)
-			die("unrecoverable error: could not open \"%s\": %s\n",
-			    pathname, strerror(errno));
+		if (len) {
+			char *buf;
 
-		slen = read(fd, dt, len);
-		if (slen < 0)
-			die("unrecoverable error: could not read \"%s\": %s\n",
-			    pathname, strerror(errno));
-		if ((size_t)slen != len)
-			die("unrecoverable error: short read from\"%s\"\n",
-			    pathname);
+			buf = slurp_file_len(pathname, len, &slen);
+			if (slen != len)
+				die("unrecoverable error: short read from\"%s\"\n",
+				    pathname);
+
+			memcpy(dt, buf, slen);
+			free(buf);
+		}
 
 		checkprop(fn, dt, len);
 
 		dt += (len + 3)/4;
 
+		fd = open(pathname, O_RDONLY);
+		if (fd == -1)
+			die("unrecoverable error: could not open \"%s\": %s\n",
+			    pathname, strerror(errno));
+
 		if (!strcmp(dp->d_name, "reg") && usablemem_rgns.size)
 			add_usable_mem_property(fd, len);
 		add_dyn_reconf_usable_mem_property(dp, fd);
-- 
2.1.0


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH] kexec/fs2dt: Use slurp_file_len to avoid partial read of files
  2014-12-01 23:59 [PATCH] kexec/fs2dt: Use slurp_file_len to avoid partial read of files Anton Blanchard
@ 2014-12-02  1:51 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2014-12-02  1:51 UTC (permalink / raw)
  To: Anton Blanchard; +Cc: kexec

On Tue, Dec 02, 2014 at 10:59:40AM +1100, Anton Blanchard wrote:
> The OPAL firmware is going to embed its symbol map in the device tree.
> The size is large enough to be more than a page, and it takes
> multiple reads to get the whole file. This is because sysfs uses
> the seq_file helpers which do a page at a time.
> 
> Unfortunately fs2dt has no handling for short reads and we die with:
> 
> unrecoverable error: short read from"/proc/device-tree//ibm,opal/firmware/symbol-map"
> 
> This patch uses the slurp_file_len helper which does the right thing.
> It moves the explicit open of the file further down for
> add_usable_mem_property and add_dyn_reconf_usable_mem_property.
> We should convert both of these to use the buffer provided by
> slurp_file_len at some stage.
> 
> Signed-off-by: Anton Blanchard <anton@samba.org>

Thanks, applied.

> ---
>  kexec/fs2dt.c | 30 +++++++++++++++++-------------
>  1 file changed, 17 insertions(+), 13 deletions(-)
> 
> diff --git a/kexec/fs2dt.c b/kexec/fs2dt.c
> index 304f6cb..3b4432d 100644
> --- a/kexec/fs2dt.c
> +++ b/kexec/fs2dt.c
> @@ -381,8 +381,8 @@ static void putprops(char *fn, struct dirent **nlist, int numlist)
>  {
>  	struct dirent *dp;
>  	int i = 0, fd;
> -	size_t len;
> -	ssize_t slen;
> +	off_t len;
> +	off_t slen;
>  	struct stat statbuf;
>  
>  	for (i = 0; i < numlist; i++) {
> @@ -443,23 +443,27 @@ static void putprops(char *fn, struct dirent **nlist, int numlist)
>  		*dt++ = cpu_to_be32(propnum(fn));
>  		pad_structure_block(len);
>  
> -		fd = open(pathname, O_RDONLY);
> -		if (fd == -1)
> -			die("unrecoverable error: could not open \"%s\": %s\n",
> -			    pathname, strerror(errno));
> +		if (len) {
> +			char *buf;
>  
> -		slen = read(fd, dt, len);
> -		if (slen < 0)
> -			die("unrecoverable error: could not read \"%s\": %s\n",
> -			    pathname, strerror(errno));
> -		if ((size_t)slen != len)
> -			die("unrecoverable error: short read from\"%s\"\n",
> -			    pathname);
> +			buf = slurp_file_len(pathname, len, &slen);
> +			if (slen != len)
> +				die("unrecoverable error: short read from\"%s\"\n",
> +				    pathname);
> +
> +			memcpy(dt, buf, slen);
> +			free(buf);
> +		}
>  
>  		checkprop(fn, dt, len);
>  
>  		dt += (len + 3)/4;
>  
> +		fd = open(pathname, O_RDONLY);
> +		if (fd == -1)
> +			die("unrecoverable error: could not open \"%s\": %s\n",
> +			    pathname, strerror(errno));
> +
>  		if (!strcmp(dp->d_name, "reg") && usablemem_rgns.size)
>  			add_usable_mem_property(fd, len);
>  		add_dyn_reconf_usable_mem_property(dp, fd);
> -- 
> 2.1.0
> 

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

end of thread, other threads:[~2014-12-02  1:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-01 23:59 [PATCH] kexec/fs2dt: Use slurp_file_len to avoid partial read of files Anton Blanchard
2014-12-02  1:51 ` Simon Horman

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.