From patchwork Wed Feb 23 14:00:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1596698 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=InqvV1lh; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K3d4T4gCfz9sG7 for ; Thu, 24 Feb 2022 01:01:29 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A4DA583BAC; Wed, 23 Feb 2022 15:01:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="InqvV1lh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6EDC383C8B; Wed, 23 Feb 2022 15:01:12 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) (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 3BA8A83C1F for ; Wed, 23 Feb 2022 15:01:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x632.google.com with SMTP id gb39so52763874ejc.1 for ; Wed, 23 Feb 2022 06:01:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kvuX4eOmZfdA9E65RQaXvqEhPRSRSzH+SSGAfIcrMqs=; b=InqvV1lhBnNFMG1jGgFDvA9OeXstfsJaJpj8CwbuAUOyRm7RmD3aOW5u2PNdW0g4c2 yUgrX4ZwZ1T6yCkk3MwO2Y4iJnj8XX9gRCaHl/L8COG0E6k5We8SXTVMK9LW75pARTB2 hPCB9MrnPEZ3drP9NNcL8QtvorjLkqVN74+JDvxFspCgpsB8MyoQUR6iydCKgahJR8+D Ij8g7FULZSMdaY17GnkM3sQwRg3Xdw/cumwDWBJg1ZGoSWFicCwfHi0sasIHtDve3MIs QsU+Ar4lidbqzcyosNIdBIwF/xMqIwUDvBu0o37RRizTo2sOQfhfxJt+uMlTBNR5q1mq j/bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=kvuX4eOmZfdA9E65RQaXvqEhPRSRSzH+SSGAfIcrMqs=; b=ia0A3T2iTcJVBwZvS52Wis8mnS6t5jcnK286EvsKB4VkE87XE38PdSyv31csrDhh54 sPzmnLCMW0Hw7tCVUg3v20fBkAIcPob1rnZfuswWgDYAqKrteDxBVCZtUlmu9YRxBhQR bNRu1GwlA3uSn5PGyOf7zgdLwtAx4HNOhnNu/LCyvcZP2JvNWyi4XJ3BzFzhj+aHA/C/ zQoRhZUQbkYWZmy/gluSP9Hodq3mzGXxXeqTEedtizk5F4SBxdkw969LA8Y6kJdqcZ8H XRMfMB0PW47mtuduZV6oWT4rtKOXLxTpwPD/eY2jEhmNClIFFef2KRKQz3djaNPAEG3B AOXA== X-Gm-Message-State: AOAM532VCu/aMtyLMNu2lmEIgXB2tCLJSxpVH2jgm1Ow07k85eWkTuPB 7NanZuNV540pvyGSRCHVcyWc6CIwcV2IfQ== X-Google-Smtp-Source: ABdhPJxHUMbqsLh3Ch49jthyJwfp3L3spfrzTiFWKToZq7geuDbq5cbYGgwJu8F43/8WaTWHIYyC0A== X-Received: by 2002:a17:906:2c12:b0:6ce:88f7:474a with SMTP id e18-20020a1709062c1200b006ce88f7474amr22217704ejh.166.1645624867543; Wed, 23 Feb 2022 06:01:07 -0800 (PST) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id dx7sm6727461ejb.23.2022.02.23.06.01.06 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Feb 2022 06:01:07 -0800 (PST) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Ashok Reddy Soma Subject: [PATCH 2/4] fru: ops: Return error from checksum if data is all zero's Date: Wed, 23 Feb 2022 15:00:57 +0100 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean From: Ashok Reddy Soma fru_checksum function is simply adding all the bytes and returning the sum. If the data passed to this function is all zero's then it will return 0, and the functions calling this api will assume that checksum is correct. Ideally this is not good. Fix this by returning error if all the data is 0's. Signed-off-by: Ashok Reddy Soma Signed-off-by: Michal Simek --- board/xilinx/common/fru_ops.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/board/xilinx/common/fru_ops.c b/board/xilinx/common/fru_ops.c index a0a1441a8eef..058e750c442f 100644 --- a/board/xilinx/common/fru_ops.c +++ b/board/xilinx/common/fru_ops.c @@ -39,12 +39,20 @@ static int fru_check_language(u8 code) u8 fru_checksum(u8 *addr, u8 len) { u8 checksum = 0; + u8 cnt = len; while (len--) { + if (*addr == 0) + cnt--; + checksum += *addr; addr++; } + /* If all data bytes are 0's return error */ + if (!cnt) + return EINVAL; + return checksum; }