Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E1732ECAAD1 for ; Sat, 27 Aug 2022 17:48:32 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 45C5284564; Sat, 27 Aug 2022 19:48:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KGql32QF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DF7508457E; Sat, 27 Aug 2022 19:48:28 +0200 (CEST) Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7DAD884001 for ; Sat, 27 Aug 2022 19:48:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ovpanait@gmail.com Received: by mail-ej1-x631.google.com with SMTP id cu2so8504098ejb.0 for ; Sat, 27 Aug 2022 10:48:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc; bh=beTAJV59omyRLxf/pwD6/hMKW0/gNAaquCDNbhlgywY=; b=KGql32QFadWOcaxAWciMwLQ+bN9CY2Sv2uE0kkp9uVP4VxcvwAzDotCmHQj7DVoCzs lgipeJhf5gwFCuU8S9DLPEWnh/9REr/OC40fCyclIeJWZUyT+lFOuaFZxb7Ltbz6xBWg 1xHgVdoEt2jtxVAggESWF8y6c7TdElriigUfGWb6uK+GJXtrxteY4UWzSof7lO6hEt7b v/G9h+RdWYZvWQTvlpcdS34wL+H91iarXYGgdMbxZ4qc/tJZrck5GI4iHVnnUrunQIha oNF5lLXqw45O1Dq3QnnxuYAqvQ25BO5SW6s3vfNIQ96A2BI1uflxajJUs/0m5Ieta8LC FzJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=beTAJV59omyRLxf/pwD6/hMKW0/gNAaquCDNbhlgywY=; b=TNTG+csGEEHcUW2H7mt1/NvD7YhxYL+fmWFgtCFT4I7jIQ+y4j08jyAzDr6nBLbsA/ m1SuvkbDXfI7Xd5tQ/MHcmfEC1NvM6vwmS3U+RGkDr+DWTaGwD/U///TDdr74UT3t2nE zdcKo16+sExgv8loAd4q+RhCd+w2coCMRzvWLskVnC7G5FPqrn2RUMzbHfbX6icwLqNF W5AhkZPY9ECWQcTWJOr/JFHDspWVuut1gWZ139KcTmMxqK8kaG3MlRQCvIZrRPTpC+zd BMQfLglA3CpurEe0eavgmv5N78fu7ChBaoAIszJESGFuufYu3pm1M+LN6kqYMoEbi6Nr a0Jw== X-Gm-Message-State: ACgBeo1isPcmSVg5JzTr0YMSVzKFYpzWvYhjfrrP26dVM0zinJEqQYQH O99yRbsfPUFW9eLTseaj0O8= X-Google-Smtp-Source: AA6agR5caRroyFQ/g7jspCtpf1O0IufvNvC2BCGjwJfAVhXyH4DBaV3NkTu3/RikU4vCnhOYPeXptQ== X-Received: by 2002:a17:907:31c9:b0:740:ef93:2ffd with SMTP id xf9-20020a17090731c900b00740ef932ffdmr4429992ejb.584.1661622506129; Sat, 27 Aug 2022 10:48:26 -0700 (PDT) Received: from ?IPV6:2a02:2f07:610e:db00:585c:d271:a9bf:8a78? ([2a02:2f07:610e:db00:585c:d271:a9bf:8a78]) by smtp.gmail.com with ESMTPSA id fw8-20020a170907500800b0073d87068042sm2261350ejc.110.2022.08.27.10.48.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 27 Aug 2022 10:48:25 -0700 (PDT) Message-ID: <352495c2-647e-c81d-39f3-f6ec146c52df@gmail.com> Date: Sat, 27 Aug 2022 20:48:24 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH 2/4] cpu: microblaze: remove unused ret variable Content-Language: en-US To: Michal Simek , u-boot@lists.denx.de Cc: Michal Simek References: <20220825064131.673958-1-ovpanait@gmail.com> <20220825064131.673958-2-ovpanait@gmail.com> <7e423cc1-5f95-fb5b-a227-dbe31aa924c6@amd.com> From: Ovidiu Panait In-Reply-To: <7e423cc1-5f95-fb5b-a227-dbe31aa924c6@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean 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 >> --- >> >>   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 > >