All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/5] sandbox/fs: Free memory allocated by os_dirent_ls
       [not found] <20161001184142.7754-1-stefan.bruens@rwth-aachen.de>
@ 2016-10-01 18:41 ` Stefan Brüns
  2016-10-03 21:49   ` Simon Glass
  2016-10-01 18:41 ` [U-Boot] [PATCH 2/5] sandbox/fs: Make linking of nodes in os_dirent_ls more obvious Stefan Brüns
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Stefan Brüns @ 2016-10-01 18:41 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
---
 fs/sandbox/sandboxfs.c |  1 +
 include/os.h           | 11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/fs/sandbox/sandboxfs.c b/fs/sandbox/sandboxfs.c
index 2703eed..cd10fd6 100644
--- a/fs/sandbox/sandboxfs.c
+++ b/fs/sandbox/sandboxfs.c
@@ -94,6 +94,7 @@ int sandbox_fs_ls(const char *dirname)
 		printf("%s %10lu %s\n", os_dirent_get_typename(node->type),
 		       node->size, node->name);
 	}
+	os_dirent_free(head);
 
 	return 0;
 }
diff --git a/include/os.h b/include/os.h
index 1782e50..049b248 100644
--- a/include/os.h
+++ b/include/os.h
@@ -215,9 +215,18 @@ struct os_dirent_node {
 int os_dirent_ls(const char *dirname, struct os_dirent_node **headp);
 
 /**
+ * Free directory list
+ *
+ * This frees a linked list containing a directory listing.
+ *
+ * @param node		Pointer to head of linked list
+ */
+void os_dirent_free(struct os_dirent_node *node);
+
+/**
  * Get the name of a directory entry type
  *
- * @param type		Type to cehck
+ * @param type		Type to check
  * @return string containing the name of that type, or "???" if none/invalid
  */
 const char *os_dirent_get_typename(enum os_dirent_t type);
-- 
2.10.0

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

* [U-Boot] [PATCH 2/5] sandbox/fs: Make linking of nodes in os_dirent_ls more obvious
       [not found] <20161001184142.7754-1-stefan.bruens@rwth-aachen.de>
  2016-10-01 18:41 ` [U-Boot] [PATCH 1/5] sandbox/fs: Free memory allocated by os_dirent_ls Stefan Brüns
@ 2016-10-01 18:41 ` Stefan Brüns
  2016-10-03 21:49   ` Simon Glass
  2016-10-01 18:41 ` [U-Boot] [PATCH 3/5] sandbox/fs: Use correct size path name buffer Stefan Brüns
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Stefan Brüns @ 2016-10-01 18:41 UTC (permalink / raw)
  To: u-boot

Previously, after reading/creating the second dirent, the second entry
would be chained to the first entry and the first entry would be linked
to head. Instead, immediately link the first entry to head.

Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
---
 arch/sandbox/cpu/os.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 2d63dd8..c71882a 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -363,8 +363,8 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
 			next->size = buf.st_size;
 		if (node)
 			node->next = next;
-		if (!head)
-			head = node;
+		else
+			head = next;
 	}
 	*headp = head;
 
-- 
2.10.0

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

* [U-Boot] [PATCH 3/5] sandbox/fs: Use correct size path name buffer
       [not found] <20161001184142.7754-1-stefan.bruens@rwth-aachen.de>
  2016-10-01 18:41 ` [U-Boot] [PATCH 1/5] sandbox/fs: Free memory allocated by os_dirent_ls Stefan Brüns
  2016-10-01 18:41 ` [U-Boot] [PATCH 2/5] sandbox/fs: Make linking of nodes in os_dirent_ls more obvious Stefan Brüns
@ 2016-10-01 18:41 ` Stefan Brüns
  2016-10-03 21:50   ` Simon Glass
  2016-10-01 18:41 ` [U-Boot] [PATCH 4/5] sandbox/fs: Set correct filetype for unknown filetype Stefan Brüns
  2016-10-01 18:41 ` [U-Boot] [PATCH 5/5] sandbox/fs: Use readdir instead of deprecated readdir_r Stefan Brüns
  4 siblings, 1 reply; 14+ messages in thread
From: Stefan Brüns @ 2016-10-01 18:41 UTC (permalink / raw)
  To: u-boot

The readdir linux manpage explicitly states (quoting POSIX.1) that
sizeof(d_name) is not correct for determining the required size, but to
always use strlen. Grow the buffer if needed.

Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
---
 arch/sandbox/cpu/os.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index c71882a..16af3f5 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -320,14 +320,16 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
 	int ret;
 	char *fname;
 	int len;
+	int dirlen;
 
 	*headp = NULL;
 	dir = opendir(dirname);
 	if (!dir)
 		return -1;
 
-	/* Create a buffer for the maximum filename length */
-	len = sizeof(entry.d_name) + strlen(dirname) + 2;
+	/* Create a buffer upfront, with typically sufficient size */
+	dirlen = strlen(dirname) + 2;
+	len = dirlen + 256;
 	fname = malloc(len);
 	if (!fname) {
 		ret = -ENOMEM;
@@ -339,7 +341,12 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
 		if (ret || !result)
 			break;
 		next = malloc(sizeof(*node) + strlen(entry.d_name) + 1);
-		if (!next) {
+		if (dirlen + strlen(entry.d_name) > len) {
+			len = dirlen + strlen(entry.d_name);
+			fname = realloc(fname, len);
+		}
+		if (!next || !fname) {
+			free(next);
 			os_dirent_free(head);
 			ret = -ENOMEM;
 			goto done;
-- 
2.10.0

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

* [U-Boot] [PATCH 4/5] sandbox/fs: Set correct filetype for unknown filetype
       [not found] <20161001184142.7754-1-stefan.bruens@rwth-aachen.de>
                   ` (2 preceding siblings ...)
  2016-10-01 18:41 ` [U-Boot] [PATCH 3/5] sandbox/fs: Use correct size path name buffer Stefan Brüns
@ 2016-10-01 18:41 ` Stefan Brüns
  2016-10-03 21:50   ` Simon Glass
  2016-10-01 18:41 ` [U-Boot] [PATCH 5/5] sandbox/fs: Use readdir instead of deprecated readdir_r Stefan Brüns
  4 siblings, 1 reply; 14+ messages in thread
From: Stefan Brüns @ 2016-10-01 18:41 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
---
 arch/sandbox/cpu/os.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 16af3f5..df2bd4c 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -363,6 +363,8 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
 		case DT_LNK:
 			next->type = OS_FILET_LNK;
 			break;
+		default:
+			next->type = OS_FILET_UNKNOWN;
 		}
 		next->size = 0;
 		snprintf(fname, len, "%s/%s", dirname, next->name);
-- 
2.10.0

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

* [U-Boot] [PATCH 5/5] sandbox/fs: Use readdir instead of deprecated readdir_r
       [not found] <20161001184142.7754-1-stefan.bruens@rwth-aachen.de>
                   ` (3 preceding siblings ...)
  2016-10-01 18:41 ` [U-Boot] [PATCH 4/5] sandbox/fs: Set correct filetype for unknown filetype Stefan Brüns
@ 2016-10-01 18:41 ` Stefan Brüns
  2016-10-03 21:50   ` Simon Glass
  4 siblings, 1 reply; 14+ messages in thread
From: Stefan Brüns @ 2016-10-01 18:41 UTC (permalink / raw)
  To: u-boot

Using readdir_r limits the maximum file name length and may even be
unsafe, and is thus deprecated in since glibc 2.24.

Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
---
 arch/sandbox/cpu/os.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index df2bd4c..35ea00c 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -313,7 +313,7 @@ void os_dirent_free(struct os_dirent_node *node)
 
 int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
 {
-	struct dirent entry, *result;
+	struct dirent *entry;
 	struct os_dirent_node *head, *node, *next;
 	struct stat buf;
 	DIR *dir;
@@ -337,12 +337,15 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
 	}
 
 	for (node = head = NULL;; node = next) {
-		ret = readdir_r(dir, &entry, &result);
-		if (ret || !result)
+		errno = 0;
+		entry = readdir(dir);
+		if (!entry) {
+			ret = errno;
 			break;
-		next = malloc(sizeof(*node) + strlen(entry.d_name) + 1);
-		if (dirlen + strlen(entry.d_name) > len) {
-			len = dirlen + strlen(entry.d_name);
+		}
+		next = malloc(sizeof(*node) + strlen(entry->d_name) + 1);
+		if (dirlen + strlen(entry->d_name) > len) {
+			len = dirlen + strlen(entry->d_name);
 			fname = realloc(fname, len);
 		}
 		if (!next || !fname) {
@@ -352,8 +355,8 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
 			goto done;
 		}
 		next->next = NULL;
-		strcpy(next->name, entry.d_name);
-		switch (entry.d_type) {
+		strcpy(next->name, entry->d_name);
+		switch (entry->d_type) {
 		case DT_REG:
 			next->type = OS_FILET_REG;
 			break;
-- 
2.10.0

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

* [U-Boot] [PATCH 1/5] sandbox/fs: Free memory allocated by os_dirent_ls
  2016-10-01 18:41 ` [U-Boot] [PATCH 1/5] sandbox/fs: Free memory allocated by os_dirent_ls Stefan Brüns
@ 2016-10-03 21:49   ` Simon Glass
  2016-10-11  0:29     ` Simon Glass
  0 siblings, 1 reply; 14+ messages in thread
From: Simon Glass @ 2016-10-03 21:49 UTC (permalink / raw)
  To: u-boot

On 1 October 2016 at 12:41, Stefan Br?ns <stefan.bruens@rwth-aachen.de> wrote:
> Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
> ---
>  fs/sandbox/sandboxfs.c |  1 +
>  include/os.h           | 11 ++++++++++-
>  2 files changed, 11 insertions(+), 1 deletion(-)

Acked-by: Simon Glass <sjg@chromium.org>

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

* [U-Boot] [PATCH 2/5] sandbox/fs: Make linking of nodes in os_dirent_ls more obvious
  2016-10-01 18:41 ` [U-Boot] [PATCH 2/5] sandbox/fs: Make linking of nodes in os_dirent_ls more obvious Stefan Brüns
@ 2016-10-03 21:49   ` Simon Glass
  2016-10-11  0:29     ` Simon Glass
  0 siblings, 1 reply; 14+ messages in thread
From: Simon Glass @ 2016-10-03 21:49 UTC (permalink / raw)
  To: u-boot

On 1 October 2016 at 12:41, Stefan Br?ns <stefan.bruens@rwth-aachen.de> wrote:
> Previously, after reading/creating the second dirent, the second entry
> would be chained to the first entry and the first entry would be linked
> to head. Instead, immediately link the first entry to head.
>
> Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
> ---
>  arch/sandbox/cpu/os.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Acked-by: Simon Glass <sjg@chromium.org>

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

* [U-Boot] [PATCH 3/5] sandbox/fs: Use correct size path name buffer
  2016-10-01 18:41 ` [U-Boot] [PATCH 3/5] sandbox/fs: Use correct size path name buffer Stefan Brüns
@ 2016-10-03 21:50   ` Simon Glass
  2016-10-11  0:29     ` Simon Glass
  0 siblings, 1 reply; 14+ messages in thread
From: Simon Glass @ 2016-10-03 21:50 UTC (permalink / raw)
  To: u-boot

On 1 October 2016 at 12:41, Stefan Br?ns <stefan.bruens@rwth-aachen.de> wrote:
> The readdir linux manpage explicitly states (quoting POSIX.1) that
> sizeof(d_name) is not correct for determining the required size, but to
> always use strlen. Grow the buffer if needed.
>
> Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
> ---
>  arch/sandbox/cpu/os.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)

Acked-by: Simon Glass <sjg@chromium.org>

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

* [U-Boot] [PATCH 5/5] sandbox/fs: Use readdir instead of deprecated readdir_r
  2016-10-01 18:41 ` [U-Boot] [PATCH 5/5] sandbox/fs: Use readdir instead of deprecated readdir_r Stefan Brüns
@ 2016-10-03 21:50   ` Simon Glass
  2016-10-11  0:29     ` Simon Glass
  0 siblings, 1 reply; 14+ messages in thread
From: Simon Glass @ 2016-10-03 21:50 UTC (permalink / raw)
  To: u-boot

On 1 October 2016 at 12:41, Stefan Br?ns <stefan.bruens@rwth-aachen.de> wrote:
> Using readdir_r limits the maximum file name length and may even be
> unsafe, and is thus deprecated in since glibc 2.24.
>
> Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
> ---
>  arch/sandbox/cpu/os.c | 19 +++++++++++--------
>  1 file changed, 11 insertions(+), 8 deletions(-)

Acked-by: Simon Glass <sjg@chromium.org>

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

* [U-Boot] [PATCH 4/5] sandbox/fs: Set correct filetype for unknown filetype
  2016-10-01 18:41 ` [U-Boot] [PATCH 4/5] sandbox/fs: Set correct filetype for unknown filetype Stefan Brüns
@ 2016-10-03 21:50   ` Simon Glass
  0 siblings, 0 replies; 14+ messages in thread
From: Simon Glass @ 2016-10-03 21:50 UTC (permalink / raw)
  To: u-boot

Hi Stefan,

On 1 October 2016 at 12:41, Stefan Br?ns <stefan.bruens@rwth-aachen.de> wrote:

Please can you add a short commit message?

> Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
> ---
>  arch/sandbox/cpu/os.c | 2 ++
>  1 file changed, 2 insertions(+)

Acked-by: Simon Glass <sjg@chromium.org>

>
> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
> index 16af3f5..df2bd4c 100644
> --- a/arch/sandbox/cpu/os.c
> +++ b/arch/sandbox/cpu/os.c
> @@ -363,6 +363,8 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
>                 case DT_LNK:
>                         next->type = OS_FILET_LNK;
>                         break;
> +               default:
> +                       next->type = OS_FILET_UNKNOWN;
>                 }
>                 next->size = 0;
>                 snprintf(fname, len, "%s/%s", dirname, next->name);
> --
> 2.10.0
>

Regards,
Simon

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

* [U-Boot] [PATCH 1/5] sandbox/fs: Free memory allocated by os_dirent_ls
  2016-10-03 21:49   ` Simon Glass
@ 2016-10-11  0:29     ` Simon Glass
  0 siblings, 0 replies; 14+ messages in thread
From: Simon Glass @ 2016-10-11  0:29 UTC (permalink / raw)
  To: u-boot

\On 3 October 2016 at 15:49, Simon Glass <sjg@chromium.org> wrote:
> On 1 October 2016 at 12:41, Stefan Br?ns <stefan.bruens@rwth-aachen.de> wrote:
>> Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
>> ---
>>  fs/sandbox/sandboxfs.c |  1 +
>>  include/os.h           | 11 ++++++++++-
>>  2 files changed, 11 insertions(+), 1 deletion(-)
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!

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

* [U-Boot] [PATCH 2/5] sandbox/fs: Make linking of nodes in os_dirent_ls more obvious
  2016-10-03 21:49   ` Simon Glass
@ 2016-10-11  0:29     ` Simon Glass
  0 siblings, 0 replies; 14+ messages in thread
From: Simon Glass @ 2016-10-11  0:29 UTC (permalink / raw)
  To: u-boot

On 3 October 2016 at 15:49, Simon Glass <sjg@chromium.org> wrote:
> On 1 October 2016 at 12:41, Stefan Br?ns <stefan.bruens@rwth-aachen.de> wrote:
>> Previously, after reading/creating the second dirent, the second entry
>> would be chained to the first entry and the first entry would be linked
>> to head. Instead, immediately link the first entry to head.
>>
>> Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
>> ---
>>  arch/sandbox/cpu/os.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!

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

* [U-Boot] [PATCH 3/5] sandbox/fs: Use correct size path name buffer
  2016-10-03 21:50   ` Simon Glass
@ 2016-10-11  0:29     ` Simon Glass
  0 siblings, 0 replies; 14+ messages in thread
From: Simon Glass @ 2016-10-11  0:29 UTC (permalink / raw)
  To: u-boot

On 3 October 2016 at 15:50, Simon Glass <sjg@chromium.org> wrote:
> On 1 October 2016 at 12:41, Stefan Br?ns <stefan.bruens@rwth-aachen.de> wrote:
>> The readdir linux manpage explicitly states (quoting POSIX.1) that
>> sizeof(d_name) is not correct for determining the required size, but to
>> always use strlen. Grow the buffer if needed.
>>
>> Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
>> ---
>>  arch/sandbox/cpu/os.c | 13 ++++++++++---
>>  1 file changed, 10 insertions(+), 3 deletions(-)
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!

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

* [U-Boot] [PATCH 5/5] sandbox/fs: Use readdir instead of deprecated readdir_r
  2016-10-03 21:50   ` Simon Glass
@ 2016-10-11  0:29     ` Simon Glass
  0 siblings, 0 replies; 14+ messages in thread
From: Simon Glass @ 2016-10-11  0:29 UTC (permalink / raw)
  To: u-boot

On 3 October 2016 at 15:50, Simon Glass <sjg@chromium.org> wrote:
> On 1 October 2016 at 12:41, Stefan Br?ns <stefan.bruens@rwth-aachen.de> wrote:
>> Using readdir_r limits the maximum file name length and may even be
>> unsafe, and is thus deprecated in since glibc 2.24.
>>
>> Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
>> ---
>>  arch/sandbox/cpu/os.c | 19 +++++++++++--------
>>  1 file changed, 11 insertions(+), 8 deletions(-)
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!

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

end of thread, other threads:[~2016-10-11  0:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20161001184142.7754-1-stefan.bruens@rwth-aachen.de>
2016-10-01 18:41 ` [U-Boot] [PATCH 1/5] sandbox/fs: Free memory allocated by os_dirent_ls Stefan Brüns
2016-10-03 21:49   ` Simon Glass
2016-10-11  0:29     ` Simon Glass
2016-10-01 18:41 ` [U-Boot] [PATCH 2/5] sandbox/fs: Make linking of nodes in os_dirent_ls more obvious Stefan Brüns
2016-10-03 21:49   ` Simon Glass
2016-10-11  0:29     ` Simon Glass
2016-10-01 18:41 ` [U-Boot] [PATCH 3/5] sandbox/fs: Use correct size path name buffer Stefan Brüns
2016-10-03 21:50   ` Simon Glass
2016-10-11  0:29     ` Simon Glass
2016-10-01 18:41 ` [U-Boot] [PATCH 4/5] sandbox/fs: Set correct filetype for unknown filetype Stefan Brüns
2016-10-03 21:50   ` Simon Glass
2016-10-01 18:41 ` [U-Boot] [PATCH 5/5] sandbox/fs: Use readdir instead of deprecated readdir_r Stefan Brüns
2016-10-03 21:50   ` Simon Glass
2016-10-11  0:29     ` Simon Glass

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.