u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Ovidiu Panait <ovpanait@gmail.com>
To: Michal Simek <michal.simek@amd.com>, u-boot@lists.denx.de
Cc: Michal Simek <monstr@monstr.eu>
Subject: Re: [PATCH 2/4] cpu: microblaze: remove unused ret variable
Date: Sat, 27 Aug 2022 20:48:24 +0300	[thread overview]
Message-ID: <352495c2-647e-c81d-39f3-f6ec146c52df@gmail.com> (raw)
In-Reply-To: <7e423cc1-5f95-fb5b-a227-dbe31aa924c6@amd.com>

Hi Michal,

On 8/25/22 11:59, Michal Simek wrote:
>
>
> On 8/25/22 08:41, Ovidiu Panait wrote:
>> Drop the unused ret variable from microblaze_cpu_get_desc().
>>
>> Signed-off-by: Ovidiu Panait <ovpanait@gmail.com>
>> ---
>>
>>   drivers/cpu/microblaze_cpu.c | 7 +++----
>>   1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/cpu/microblaze_cpu.c b/drivers/cpu/microblaze_cpu.c
>> index 969a1047e5..4eae06a8a6 100644
>> --- a/drivers/cpu/microblaze_cpu.c
>> +++ b/drivers/cpu/microblaze_cpu.c
>> @@ -88,15 +88,14 @@ static int microblaze_cpu_get_desc(const struct 
>> udevice *dev, char *buf,
>>       struct microblaze_cpuinfo *ci = gd_cpuinfo();
>>       const char *cpu_ver, *fpga_family;
>>       u32 cpu_freq_mhz;
>> -    int ret;
>>         cpu_freq_mhz = ci->cpu_freq / 1000000;
>>       cpu_ver = microblaze_lookup_cpu_version_string(ci->ver_code);
>>       fpga_family = microblaze_lookup_fpga_family_string(ci->fpga_code);
>>   -    ret = snprintf(buf, size,
>> -               "MicroBlaze @ %uMHz, Rev: %s, FPGA family: %s",
>> -               cpu_freq_mhz, cpu_ver, fpga_family);
>> +    snprintf(buf, size,
>> +         "MicroBlaze @ %uMHz, Rev: %s, FPGA family: %s",
>> +         cpu_freq_mhz, cpu_ver, fpga_family);
>>         return 0;
>>   }
>
> First of all I think you can remove DECLARE_GLOBAL_DATA_PTR from 
> drivers/cpu/microblaze_cpu.c
>
gd_cpuinfo() macro expands to "(struct microblaze_cpuinfo 
*)&gd->arch.cpuinfo", so we need the declaration for gd.


> I looked at the code and I think that there are some things what 
> should happen.
> First of all I would memset by 0 that buf which is passed and I think 
> this should be done in uclass to make sure that you won't show 
> anything what it is on the stack where buf is allocated in cmd/cpu.c 
> for example.
>
I don't think that the memset is necessary, snprintf will overwrite any 
previous contents and append the terminating null character after the 
last byte that was written to the buffer. So no garbage previously 
present on the stack should be printed when buf is used afterwards, as 
the string is null-terminated.


> The second if snprintf fails we shouldn't ignore that error because if 
> you do that that means that buffer is valid and you can print content.
>
> For cpu_freq_mhz I think that make sense to allocate some space in 
> string. For example %4u gives you exact size GHz should be fine for 
> now. cpu_ver has max size 6 now and family string has 18 chars now.
>
>
> It means change string to this with some chars on the top should be 
> fine for me.
>     ret = snprintf(buf, size,
>          "MicroBlaze @ %5uMHz, Rev: %7s, FPGA family: %20s",
>          cpu_freq_mhz, cpu_ver, fpga_family);
>
>
> And then check that ret is equal XX size would be easy for checking 
> and returning 0 if they match.

I agree, the snprintf errors should be handled properly here.


Thanks,

Ovidiu

>
> Thanks,
> Michal
>
>

  reply	other threads:[~2022-08-27 17:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-25  6:41 [PATCH 1/4] microblaze: drop CONFIG_SYS_INIT_RAM_ADDR and CONFIG_SYS_INIT_RAM_SIZE Ovidiu Panait
2022-08-25  6:41 ` [PATCH 2/4] cpu: microblaze: remove unused ret variable Ovidiu Panait
2022-08-25  8:59   ` Michal Simek
2022-08-27 17:48     ` Ovidiu Panait [this message]
2022-08-25  6:41 ` [PATCH 3/4] cmd: bdinfo: introduce bdinfo_print_size() helper Ovidiu Panait
2022-08-25  9:06   ` Michal Simek
2022-08-25 15:01   ` Simon Glass
2022-08-25  6:41 ` [PATCH 4/4] microblaze: add arch_print_bdinfo() implementation Ovidiu Panait
2022-08-25  9:04   ` Michal Simek
2022-08-25  8:43 ` [PATCH 1/4] microblaze: drop CONFIG_SYS_INIT_RAM_ADDR and CONFIG_SYS_INIT_RAM_SIZE Michal Simek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=352495c2-647e-c81d-39f3-f6ec146c52df@gmail.com \
    --to=ovpanait@gmail.com \
    --cc=michal.simek@amd.com \
    --cc=monstr@monstr.eu \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).