* [PATCH v2 1/3] dm: fix up documentation for uclass_get_by_name_len
2022-01-17 15:49 [PATCH v2 0/3] sandbox: test: activate tests for the command LOG Patrick Delaunay
@ 2022-01-17 15:49 ` Patrick Delaunay
2022-01-27 15:05 ` Simon Glass
2022-01-17 15:49 ` [PATCH v2 2/3] dm: compare full name in uclass_get_by_name Patrick Delaunay
2022-01-17 15:49 ` [PATCH v2 3/3] sandbox: test: activate tests for the command LOG Patrick Delaunay
2 siblings, 1 reply; 7+ messages in thread
From: Patrick Delaunay @ 2022-01-17 15:49 UTC (permalink / raw)
To: u-boot; +Cc: Patrick Delaunay, Simon Glass, U-Boot STM32
Fix up the comment for uclass_get_by_name_len() to avoid confusion.
Fixes: 4b030177b660 ("dm: core: Allow finding children / uclasses by partial name")
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---
(no changes since v1)
include/dm/uclass.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index f1fd2ba246..a606b6a20b 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -173,10 +173,10 @@ int uclass_get(enum uclass_id key, struct uclass **ucp);
const char *uclass_get_name(enum uclass_id id);
/**
- * uclass_get_by_name() - Look up a uclass by its driver name
+ * uclass_get_by_name_len() - Look up a uclass by its partial driver name
*
* @name: Name to look up
- * @len: Length of name
+ * @len: Length of the partial name
* @returns the associated uclass ID, or UCLASS_INVALID if not found
*/
enum uclass_id uclass_get_by_name_len(const char *name, int len);
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/3] dm: fix up documentation for uclass_get_by_name_len
2022-01-17 15:49 ` [PATCH v2 1/3] dm: fix up documentation for uclass_get_by_name_len Patrick Delaunay
@ 2022-01-27 15:05 ` Simon Glass
0 siblings, 0 replies; 7+ messages in thread
From: Simon Glass @ 2022-01-27 15:05 UTC (permalink / raw)
To: Patrick Delaunay; +Cc: U-Boot Mailing List, U-Boot STM32
On Mon, 17 Jan 2022 at 08:49, Patrick Delaunay
<patrick.delaunay@foss.st.com> wrote:
>
> Fix up the comment for uclass_get_by_name_len() to avoid confusion.
>
> Fixes: 4b030177b660 ("dm: core: Allow finding children / uclasses by partial name")
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
>
> (no changes since v1)
>
> include/dm/uclass.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Simon Glass <sjg@chromium.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 2/3] dm: compare full name in uclass_get_by_name
2022-01-17 15:49 [PATCH v2 0/3] sandbox: test: activate tests for the command LOG Patrick Delaunay
2022-01-17 15:49 ` [PATCH v2 1/3] dm: fix up documentation for uclass_get_by_name_len Patrick Delaunay
@ 2022-01-17 15:49 ` Patrick Delaunay
2022-01-27 15:05 ` Simon Glass
2022-01-17 15:49 ` [PATCH v2 3/3] sandbox: test: activate tests for the command LOG Patrick Delaunay
2 siblings, 1 reply; 7+ messages in thread
From: Patrick Delaunay @ 2022-01-17 15:49 UTC (permalink / raw)
To: u-boot; +Cc: Patrick Delaunay, Simon Glass, U-Boot STM32
Change uclass_get_by_name to use a strict string compare function
"strcmp" with the parameter 'name'.
This patch avoids issues when strlen(name)<strlen(uc_drv->name) as
the function uclass_get_by_name() no more use uclass_get_by_name_len(),
which limit the check with "strncmp" and length of name.
This problem is detected by the sandbox test for log filter:
in log_get_cat_by_name(), uclass_get_by_name("spi") = UCLASS_SPI_EMUL
for "spi_emul", it is not the expected result = UCLASS_SPI
for a search by name.
But it is the expected result for search with partial name
uclass_get_by_name_len("spi", 3).
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---
(no changes since v1)
drivers/core/uclass.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 336ea8d243..32b6cef167 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -196,7 +196,16 @@ enum uclass_id uclass_get_by_name_len(const char *name, int len)
enum uclass_id uclass_get_by_name(const char *name)
{
- return uclass_get_by_name_len(name, strlen(name));
+ int i;
+
+ for (i = 0; i < UCLASS_COUNT; i++) {
+ struct uclass_driver *uc_drv = lists_uclass_lookup(i);
+
+ if (uc_drv && !strcmp(uc_drv->name, name))
+ return i;
+ }
+
+ return UCLASS_INVALID;
}
int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp)
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/3] dm: compare full name in uclass_get_by_name
2022-01-17 15:49 ` [PATCH v2 2/3] dm: compare full name in uclass_get_by_name Patrick Delaunay
@ 2022-01-27 15:05 ` Simon Glass
0 siblings, 0 replies; 7+ messages in thread
From: Simon Glass @ 2022-01-27 15:05 UTC (permalink / raw)
To: Patrick Delaunay; +Cc: U-Boot Mailing List, U-Boot STM32
Hi Patrick,
On Mon, 17 Jan 2022 at 08:49, Patrick Delaunay
<patrick.delaunay@foss.st.com> wrote:
>
> Change uclass_get_by_name to use a strict string compare function
> "strcmp" with the parameter 'name'.
>
> This patch avoids issues when strlen(name)<strlen(uc_drv->name) as
> the function uclass_get_by_name() no more use uclass_get_by_name_len(),
> which limit the check with "strncmp" and length of name.
>
> This problem is detected by the sandbox test for log filter:
> in log_get_cat_by_name(), uclass_get_by_name("spi") = UCLASS_SPI_EMUL
> for "spi_emul", it is not the expected result = UCLASS_SPI
> for a search by name.
> But it is the expected result for search with partial name
> uclass_get_by_name_len("spi", 3).
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
>
> (no changes since v1)
>
> drivers/core/uclass.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
To save code space, could we avoid copying the function and instead
use len == -1 to mean to check the whole thing?
>
> diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
> index 336ea8d243..32b6cef167 100644
> --- a/drivers/core/uclass.c
> +++ b/drivers/core/uclass.c
> @@ -196,7 +196,16 @@ enum uclass_id uclass_get_by_name_len(const char *name, int len)
>
> enum uclass_id uclass_get_by_name(const char *name)
> {
> - return uclass_get_by_name_len(name, strlen(name));
> + int i;
> +
> + for (i = 0; i < UCLASS_COUNT; i++) {
> + struct uclass_driver *uc_drv = lists_uclass_lookup(i);
> +
> + if (uc_drv && !strcmp(uc_drv->name, name))
> + return i;
> + }
> +
> + return UCLASS_INVALID;
> }
>
> int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp)
> --
> 2.25.1
>
Regards,
Simon
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 3/3] sandbox: test: activate tests for the command LOG
2022-01-17 15:49 [PATCH v2 0/3] sandbox: test: activate tests for the command LOG Patrick Delaunay
2022-01-17 15:49 ` [PATCH v2 1/3] dm: fix up documentation for uclass_get_by_name_len Patrick Delaunay
2022-01-17 15:49 ` [PATCH v2 2/3] dm: compare full name in uclass_get_by_name Patrick Delaunay
@ 2022-01-17 15:49 ` Patrick Delaunay
2022-01-27 15:05 ` Simon Glass
2 siblings, 1 reply; 7+ messages in thread
From: Patrick Delaunay @ 2022-01-17 15:49 UTC (permalink / raw)
To: u-boot; +Cc: Patrick Delaunay, Simon Glass, U-Boot STM32
Activate the CONFIG_CMD_LOG in sandbox to execute the LOG tests
by default and correct the test log format after 72fa1ad8d9 ("log: Allow
padding of the function name").
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---
Changes in v2:
- update commit message "sandox" => "sandbox"
configs/sandbox_defconfig | 2 +-
test/py/tests/test_log.py | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 4f413582fb..a4aeee062f 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -30,7 +30,6 @@ CONFIG_AUTOBOOT_STOP_STR_CRYPT="$5$rounds=640000$HrpE65IkB8CM5nCL$BKT3QdF98Bo8fJ
CONFIG_CONSOLE_RECORD=y
CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
CONFIG_PRE_CONSOLE_BUFFER=y
-CONFIG_LOG=y
CONFIG_DISPLAY_BOARDINFO_LATE=y
CONFIG_MISC_INIT_F=y
CONFIG_STACKPROTECTOR=y
@@ -108,6 +107,7 @@ CONFIG_CMD_CRAMFS=y
CONFIG_CMD_EXT4_WRITE=y
CONFIG_CMD_SQUASHFS=y
CONFIG_CMD_MTDPARTS=y
+CONFIG_CMD_LOG=y
CONFIG_CMD_STACKPROTECTOR_TEST=y
CONFIG_MAC_PARTITION=y
CONFIG_AMIGA_PARTITION=y
diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py
index 140dcb9aa2..20a3e56301 100644
--- a/test/py/tests/test_log.py
+++ b/test/py/tests/test_log.py
@@ -27,13 +27,13 @@ def test_log_format(u_boot_console):
cons = u_boot_console
with cons.log.section('format'):
- run_with_format('all', 'NOTICE.arch,file.c:123-func() msg')
+ run_with_format('all', 'NOTICE.arch,file.c:123- func() msg')
output = cons.run_command('log format')
assert output == 'Log format: clFLfm'
- run_with_format('fm', 'func() msg')
- run_with_format('clfm', 'NOTICE.arch,func() msg')
- run_with_format('FLfm', 'file.c:123-func() msg')
+ run_with_format('fm', ' func() msg')
+ run_with_format('clfm', 'NOTICE.arch, func() msg')
+ run_with_format('FLfm', 'file.c:123- func() msg')
run_with_format('lm', 'NOTICE. msg')
run_with_format('m', 'msg')
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 3/3] sandbox: test: activate tests for the command LOG
2022-01-17 15:49 ` [PATCH v2 3/3] sandbox: test: activate tests for the command LOG Patrick Delaunay
@ 2022-01-27 15:05 ` Simon Glass
0 siblings, 0 replies; 7+ messages in thread
From: Simon Glass @ 2022-01-27 15:05 UTC (permalink / raw)
To: Patrick Delaunay; +Cc: U-Boot Mailing List, U-Boot STM32
On Mon, 17 Jan 2022 at 08:49, Patrick Delaunay
<patrick.delaunay@foss.st.com> wrote:
>
> Activate the CONFIG_CMD_LOG in sandbox to execute the LOG tests
> by default and correct the test log format after 72fa1ad8d9 ("log: Allow
> padding of the function name").
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
>
> Changes in v2:
> - update commit message "sandox" => "sandbox"
>
> configs/sandbox_defconfig | 2 +-
> test/py/tests/test_log.py | 8 ++++----
> 2 files changed, 5 insertions(+), 5 deletions(-)
>
Reviewed-by: Simon Glass <sjg@chromium.org>
activate tests for the command LOG
^ permalink raw reply [flat|nested] 7+ messages in thread