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 400DFC6FA81 for ; Mon, 29 Aug 2022 17:02:28 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 919738481B; Mon, 29 Aug 2022 19:02:21 +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="aKUaRGcr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DBBE48494B; Mon, 29 Aug 2022 19:02:15 +0200 (CEST) Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) (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 A3A7B8481B for ; Mon, 29 Aug 2022 19:02:13 +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-ed1-x529.google.com with SMTP id 2so10959330edx.2 for ; Mon, 29 Aug 2022 10:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=urVz4yavUrY2XhiFekTtqm78CyXiKFTudk0j1YtNVsw=; b=aKUaRGcrFOC4Nfzx2PCv5qEOqzGM3AO+TyNOlFaaz/EeUoYHLMe6Z2BcAcDrQH6O9q 5xkw9kYuv2HQjcjYSW0jehCKI9TFcEEXyvLhQydoMUUdVvoFpgxqnO2qfo1tE8gwhpsx juDYmbu/coRcsoeAkmRWmM+ZB1y9/4CJ7jhy0SXxzED29eN6k0UR5fHYYKDFM08oar2s eXlUyKj4hrYC+X80Ef2E94Bogwv222TtD3zmrB//K4MVHGJ/WL7ODRQvXHwVJO7ry+ks flpznc3rSVJjglm8bDUZolbJi7X8XmRxXxkYpBI2y6eURjoTp/5EBjZGTNO0LEYYaXLl 1PUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=urVz4yavUrY2XhiFekTtqm78CyXiKFTudk0j1YtNVsw=; b=3482jaqaWcNnGf4pjLJ+kRnWXrP7rBYO71ysx4Q7YhHuDynmDafPz20TNQV0LUOHTv FcgXQDxB7e/T6dLxlMPamXGCNXbzYS67g6jGr0lVXC1d8gHi5s6u/qPEPxgdSnnHpNqa 49AyT/kxGs4kEA5KT7d92N+0jdc9XiFnd5BjuyKD7moidCzafMLo7GE6wSbJk9Otyi6M Hc6OKAbesU5fBgHQaBx1qm3M31yVCf00oc+OwMaope3rylEif4tTO1Z0yO35yniTBlZ4 exJKQeMP/YWLGByIS/8GQ6xIXujC5alf3Q31l1H23IdVa8P/t+nrTRgM1Aaxj/KslQZb L8VQ== X-Gm-Message-State: ACgBeo2OEAjnrPoV+QShdhqn6qWiPioTRKs6VHSJmWhGjkU1eydqwF45 OMeqKBfETsIlUUb1IbawXMcdQcJBhaQ= X-Google-Smtp-Source: AA6agR6hPA53bl7jDq+oT/sHfuj1Z5dll3HxAKvhc0BrAe4Jppa9v3fMbAcU6cq7Om6RFV/TaBsCqQ== X-Received: by 2002:a05:6402:5489:b0:43b:b935:db37 with SMTP id fg9-20020a056402548900b0043bb935db37mr17743202edb.347.1661792533241; Mon, 29 Aug 2022 10:02:13 -0700 (PDT) Received: from wsdell.corp.ad.wrs.com ([2a02:2f07:610e:db00:a66a:9c69:59fb:17ec]) by smtp.gmail.com with ESMTPSA id g24-20020a50d0d8000000b0044786c2c5c1sm6012852edf.3.2022.08.29.10.02.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 10:02:12 -0700 (PDT) From: Ovidiu Panait To: u-boot@lists.denx.de Cc: Ovidiu Panait , Michal Simek , Michal Simek Subject: [PATCH v2 2/4] cpu: microblaze: add error handling in microblaze_cpu_get_desc() Date: Mon, 29 Aug 2022 20:02:03 +0300 Message-Id: <20220829170205.1274484-2-ovpanait@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220829170205.1274484-1-ovpanait@gmail.com> References: <20220829170205.1274484-1-ovpanait@gmail.com> MIME-Version: 1.0 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 Check snprintf() return value for errors. Make microblaze_cpu_get_desc() directly return snprintf() error code if ret < 0. Otherwise, if the return value is greater than or equal to size, the resulting string is truncated, so return -ENOSPC. Fixes: 816226d27e ("cpu: add CPU driver for microblaze") Signed-off-by: Ovidiu Panait --- Changes in v2: New patch. drivers/cpu/microblaze_cpu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/cpu/microblaze_cpu.c b/drivers/cpu/microblaze_cpu.c index 969a1047e5..b9d0792822 100644 --- a/drivers/cpu/microblaze_cpu.c +++ b/drivers/cpu/microblaze_cpu.c @@ -97,8 +97,10 @@ static int microblaze_cpu_get_desc(const struct udevice *dev, char *buf, ret = snprintf(buf, size, "MicroBlaze @ %uMHz, Rev: %s, FPGA family: %s", cpu_freq_mhz, cpu_ver, fpga_family); + if (ret < 0) + return ret; - return 0; + return (ret >= size) ? -ENOSPC : 0; } static int microblaze_cpu_get_info(const struct udevice *dev, -- 2.25.1