* [PATCH] scripts/dtc: Assign value when defining variables
@ 2021-05-18 6:07 zuoqilin1
2021-05-18 17:01 ` Rob Herring
0 siblings, 1 reply; 2+ messages in thread
From: zuoqilin1 @ 2021-05-18 6:07 UTC (permalink / raw)
To: robh+dt, frowand.list; +Cc: devicetree, linux-kernel, zuoqilin
From: zuoqilin <zuoqilin@yulong.com>
When defining variables and assigning values can be done at the same time.
Signed-off-by: zuoqilin <zuoqilin@yulong.com>
---
scripts/dtc/util.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/scripts/dtc/util.c b/scripts/dtc/util.c
index 40274fb..d1f7608 100644
--- a/scripts/dtc/util.c
+++ b/scripts/dtc/util.c
@@ -292,7 +292,7 @@ int utilfdt_write_err(const char *filename, const void *blob)
{
int fd = 1; /* assume stdout */
int totalsize;
- int offset;
+ int offset = 0;
int ret = 0;
const char *ptr = blob;
@@ -303,7 +303,6 @@ int utilfdt_write_err(const char *filename, const void *blob)
}
totalsize = fdt_totalsize(blob);
- offset = 0;
while (offset < totalsize) {
ret = write(fd, ptr + offset, totalsize - offset);
@@ -421,7 +420,7 @@ void NORETURN util_usage(const char *errmsg, const char *synopsis,
const char a_arg[] = "<arg>";
size_t a_arg_len = strlen(a_arg) + 1;
size_t i;
- int optlen;
+ int optlen = 0;
fprintf(fp,
"Usage: %s\n"
@@ -429,7 +428,6 @@ void NORETURN util_usage(const char *errmsg, const char *synopsis,
"Options: -[%s]\n", synopsis, short_opts);
/* prescan the --long opt length to auto-align */
- optlen = 0;
for (i = 0; long_opts[i].name; ++i) {
/* +1 is for space between --opt and help text */
int l = strlen(long_opts[i].name) + 1;
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] scripts/dtc: Assign value when defining variables
2021-05-18 6:07 [PATCH] scripts/dtc: Assign value when defining variables zuoqilin1
@ 2021-05-18 17:01 ` Rob Herring
0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2021-05-18 17:01 UTC (permalink / raw)
To: zuoqilin1; +Cc: Frank Rowand, devicetree, linux-kernel, zuoqilin
On Tue, May 18, 2021 at 1:07 AM <zuoqilin1@163.com> wrote:
>
> From: zuoqilin <zuoqilin@yulong.com>
We don't take patches against the kernel copy of dtc. They need to go
upstream and to the devicetree-compiler list.
> When defining variables and assigning values can be done at the same time.
>
> Signed-off-by: zuoqilin <zuoqilin@yulong.com>
> ---
> scripts/dtc/util.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/scripts/dtc/util.c b/scripts/dtc/util.c
> index 40274fb..d1f7608 100644
> --- a/scripts/dtc/util.c
> +++ b/scripts/dtc/util.c
> @@ -292,7 +292,7 @@ int utilfdt_write_err(const char *filename, const void *blob)
> {
> int fd = 1; /* assume stdout */
> int totalsize;
> - int offset;
> + int offset = 0;
> int ret = 0;
> const char *ptr = blob;
>
> @@ -303,7 +303,6 @@ int utilfdt_write_err(const char *filename, const void *blob)
> }
>
> totalsize = fdt_totalsize(blob);
> - offset = 0;
It is possible to exit before this point and the assignment is not
necessary if you do.
>
> while (offset < totalsize) {
> ret = write(fd, ptr + offset, totalsize - offset);
> @@ -421,7 +420,7 @@ void NORETURN util_usage(const char *errmsg, const char *synopsis,
> const char a_arg[] = "<arg>";
> size_t a_arg_len = strlen(a_arg) + 1;
> size_t i;
> - int optlen;
> + int optlen = 0;
>
> fprintf(fp,
> "Usage: %s\n"
> @@ -429,7 +428,6 @@ void NORETURN util_usage(const char *errmsg, const char *synopsis,
> "Options: -[%s]\n", synopsis, short_opts);
>
> /* prescan the --long opt length to auto-align */
> - optlen = 0;
In keeping with doing the assignment as late as possible and just
before needing it, this was correct as is.
> for (i = 0; long_opts[i].name; ++i) {
> /* +1 is for space between --opt and help text */
> int l = strlen(long_opts[i].name) + 1;
> --
> 1.9.1
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-18 17:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-18 6:07 [PATCH] scripts/dtc: Assign value when defining variables zuoqilin1
2021-05-18 17:01 ` Rob Herring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).