diff mbox series

[RESEND,01/12] Kconfig: Add error path in conf_value_to_yaml

Message ID 20250113-jag-bringup_fixes-v1-1-fb28030b1f26@kernel.org (mailing list archive)
State New
Headers show
Series kdevops: Various fixes | expand

Commit Message

Joel Granados Jan. 13, 2025, 11:52 a.m. UTC
The asprintf call returns -1 on error. In this case the value of
yaml_value is undefined. Return NULL, so the caller can handle the
error.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
---
 scripts/kconfig/confdata.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Comments

Luis Chamberlain Jan. 17, 2025, 9:04 p.m. UTC | #1
On Mon, Jan 13, 2025 at 12:52:59PM +0100, Joel Granados wrote:
> The asprintf call returns -1 on error. In this case the value of
> yaml_value is undefined. Return NULL, so the caller can handle the
> error.
> 
> Signed-off-by: Joel Granados <joel.granados@kernel.org>

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>

It would be good if someone other than me can get used to using
the kconfig git project with the yamlconfig branch updated first
with this patch, and then kdevops will use that as a git subtree
to update itself. It is not a requirement, however it is a nice
practice to follow.

Hopefully reading git log scripts/kconfig/ will explain how I last
did this in light of the full *new tree* which kdevops started, without
the kconfig content being a git subtree from the start, but rather as
an afterthought after the new git tree was started to trim it down.

The file Makefile.subtrees is just a helper to show how you can add
git trees locally as git sub trees and manage it / update them.

So can you merge this first onto kdevops/kconfig git tree on the
yamlconfig branch, and then use that branch to update kdevops itself?

  Luis
Joel Granados Jan. 22, 2025, 8:31 p.m. UTC | #2
On Mon, Jan 13, 2025 at 12:52:59PM +0100, Joel Granados wrote:
> The asprintf call returns -1 on error. In this case the value of
> yaml_value is undefined. Return NULL, so the caller can handle the
> error.
> 
> Signed-off-by: Joel Granados <joel.granados@kernel.org>
> ---
>  scripts/kconfig/confdata.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> index 0156b38..49a5729 100644
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
> @@ -669,14 +669,14 @@ static char *conf_value_to_yaml(struct symbol *sym, const char *val)
>  		yaml_value = strdup(val);
>  		break;
>  	case S_HEX:
This is no good as I removed the breaks. And so the execution will just
fall through when it is not supposed to.
> -            asprintf(&yaml_value, "0x%s", val);
> -            break;
> -        case S_STRING:
> -	    /* Wrap strings in quotes */
> -            asprintf(&yaml_value, "\"%s\"", val);
> -            break;
> -        case S_BOOLEAN:
> -        case S_TRISTATE:
> +		if (asprintf(&yaml_value, "0x%s", val) < 0)
> +			return NULL;
Missed a break
> +	case S_STRING:
> +		/* Wrap strings in quotes */
> +		if (asprintf(&yaml_value, "\"%s\"", val) < 0)
> +			return NULL;
Missed a break
> +	case S_BOOLEAN:
> +	case S_TRISTATE:
>  		if (strcmp(val, "y") == 0)
>  			yaml_value = strdup("True");
>  		else if (strcmp(val, "n") == 0)
> 
> -- 
> 2.44.2
> 
>
Joel Granados Jan. 22, 2025, 8:37 p.m. UTC | #3
On Fri, Jan 17, 2025 at 01:04:14PM -0800, Luis Chamberlain wrote:
> On Mon, Jan 13, 2025 at 12:52:59PM +0100, Joel Granados wrote:
> > The asprintf call returns -1 on error. In this case the value of
> > yaml_value is undefined. Return NULL, so the caller can handle the
> > error.
> > 
> > Signed-off-by: Joel Granados <joel.granados@kernel.org>
> 
> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Thx for the review.

> 
> It would be good if someone other than me can get used to using
> the kconfig git project with the yamlconfig branch updated first
> with this patch, and then kdevops will use that as a git subtree
> to update itself. It is not a requirement, however it is a nice
> practice to follow.
I completely missed this. Thx for pointing it out.

This is what I'll do:
1. Fix my patch and readd the "breaks"
2. Push them to the yamlconfig branch
3. Update the subtree in kdevops with the following command
   `git subtree pull --prefix=scripts/kconfig git@github.com:linux-kdevops/kconfig.git yamlconfig`

Best
Joel Granados Jan. 22, 2025, 9:29 p.m. UTC | #4
On Wed, Jan 22, 2025 at 09:37:42PM +0100, Joel Granados wrote:
> On Fri, Jan 17, 2025 at 01:04:14PM -0800, Luis Chamberlain wrote:
> > On Mon, Jan 13, 2025 at 12:52:59PM +0100, Joel Granados wrote:
> > > The asprintf call returns -1 on error. In this case the value of
> > > yaml_value is undefined. Return NULL, so the caller can handle the
> > > error.
> > > 
> > > Signed-off-by: Joel Granados <joel.granados@kernel.org>
> > 
> > Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
> Thx for the review.
> 
> > 
> > It would be good if someone other than me can get used to using
> > the kconfig git project with the yamlconfig branch updated first
> > with this patch, and then kdevops will use that as a git subtree
> > to update itself. It is not a requirement, however it is a nice
> > practice to follow.
> I completely missed this. Thx for pointing it out.
> 
> This is what I'll do:
> 1. Fix my patch and readd the "breaks"
This is done
> 2. Push them to the yamlconfig branch
This is done
> 3. Update the subtree in kdevops with the following command
>    `git subtree pull --prefix=scripts/kconfig git@github.com:linux-kdevops/kconfig.git yamlconfig`
I added a --squash at the end of this command. BTW
When I do this, it makes a merge commit. Is that ok? I don't see to many
of those and thought I ask before pushing.
> 
> Best
> -- 
> 
> Joel Granados
Joel Granados Jan. 27, 2025, 1:56 p.m. UTC | #5
On Wed, Jan 22, 2025 at 05:02:16PM -0600, Luis Chamberlain wrote:
> On Wed, Jan 22, 2025, 3:30 PM Joel Granados <joel.granados@kernel.org>
> wrote:
> 
> >
> > > 3. Update the subtree in kdevops with the following command
> > >    `git subtree pull --prefix=scripts/kconfig git@github.com:linux-kdevops/kconfig.git
> > yamlconfig`
> > I added a --squash at the end of this command. BTW
> > When I do this, it makes a merge commit. Is that ok? I don't see to many
> > of those and thought I ask before pushing.
> >
> 
> Yes ! That's exactly what is expected.
perfect. I'll push to main then

Best
diff mbox series

Patch

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 0156b38..49a5729 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -669,14 +669,14 @@  static char *conf_value_to_yaml(struct symbol *sym, const char *val)
 		yaml_value = strdup(val);
 		break;
 	case S_HEX:
-            asprintf(&yaml_value, "0x%s", val);
-            break;
-        case S_STRING:
-	    /* Wrap strings in quotes */
-            asprintf(&yaml_value, "\"%s\"", val);
-            break;
-        case S_BOOLEAN:
-        case S_TRISTATE:
+		if (asprintf(&yaml_value, "0x%s", val) < 0)
+			return NULL;
+	case S_STRING:
+		/* Wrap strings in quotes */
+		if (asprintf(&yaml_value, "\"%s\"", val) < 0)
+			return NULL;
+	case S_BOOLEAN:
+	case S_TRISTATE:
 		if (strcmp(val, "y") == 0)
 			yaml_value = strdup("True");
 		else if (strcmp(val, "n") == 0)