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 BFDA8C7619A for ; Mon, 27 Mar 2023 11:02:29 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7E8F186095; Mon, 27 Mar 2023 13:01:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=metanate.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=metanate.com header.i=@metanate.com header.b="kdk4Hpe3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BE0B786070; Mon, 27 Mar 2023 13:01:28 +0200 (CEST) Received: from metanate.com (unknown [IPv6:2001:8b0:1628:5005::111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DEBA286050 for ; Mon, 27 Mar 2023 13:01:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=metanate.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=john@metanate.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metanate.com; s=stronger; h=Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Content-Type:Reply-To: Content-ID:Content-Description; bh=fYVm1mcoULKqjc/uh7rCV2vIS6fY1GySRd1A79xaJ/A=; b=kdk4Hpe3uagF+KW94izqB1piTI 4QTFsjTHfL87vmcxu2bvU73aPBNNMrZfQlNVxI3M70aSH0Tdb/fdRpE2RS4BNqzsM5RiaYVHBFw8n q++D1vCi97YzrUElwDBCznyUoxi7wgbO1jvikTQdneByZTZQE6B3Z73hI02vFy42paOfwETD73LlS JLkuuG8TbOd7GVtHOrE28jNjGszeN8m+m2DTqD7Ys/i/1JOMozOYe6J5FJyzeYUwEqq2V2MGbO7zc WAP0LKbves99RbGSnOdTHUDBeNkDqPLlfeSxWIWHQDA7vS7UnNIQHbnDbRkMZ5RP8WODPMW7630zF knfvyPjQ==; Received: from [81.174.171.191] (helo=donbot.metanate.com) by email.metanate.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pgkbF-00079X-Rr; Mon, 27 Mar 2023 12:01:19 +0100 From: John Keeping To: u-boot@lists.denx.de Cc: Simon Glass , Philipp Tomsich , Kever Yang , Jonas Karlman , John Keeping Subject: [PATCH v3 2/3] rockchip: efuse: fix misc_read() return values Date: Mon, 27 Mar 2023 12:01:09 +0100 Message-Id: <20230327110110.1312992-3-john@metanate.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230327110110.1312992-1-john@metanate.com> References: <20230327110110.1312992-1-john@metanate.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authenticated: YES 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.8 at phobos.denx.de X-Virus-Status: Clean The documentation for misc_read() says: Return: number of bytes read if OK (may be 0 if EOF), -ve on error The Rockchip efuse driver implements this so it should return the number of bytes read rather than zero on success. Fix this so that the driver follows the usual contract for read operations. Reviewed-by: Simon Glass Reviewed-by: Jonas Karlman Signed-off-by: John Keeping --- v3: unchanged v2: - Fix when block_size > 1 by moving the return value to the main rockchip_efuse_read() wrapper and leaving the individual implementations alone (Jonas) drivers/misc/rockchip-efuse.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/misc/rockchip-efuse.c b/drivers/misc/rockchip-efuse.c index 60931a5131..2f96b79ea4 100644 --- a/drivers/misc/rockchip-efuse.c +++ b/drivers/misc/rockchip-efuse.c @@ -73,7 +73,7 @@ static int dump_efuse(struct cmd_tbl *cmdtp, int flag, for (i = 0; true; i += sizeof(data)) { ret = misc_read(dev, i, &data, sizeof(data)); - if (ret < 0) + if (ret <= 0) return 0; print_buffer(i, data, 1, sizeof(data), sizeof(data)); @@ -238,8 +238,10 @@ static int rockchip_efuse_read(struct udevice *dev, int offset, offset += data->offset; - if (data->block_size <= 1) - return data->read(dev, offset, buf, size); + if (data->block_size <= 1) { + ret = data->read(dev, offset, buf, size); + goto done; + } block_start = offset / data->block_size; block_offset = offset % data->block_size; @@ -255,7 +257,9 @@ static int rockchip_efuse_read(struct udevice *dev, int offset, memcpy(buf, buffer + block_offset, size); free(buffer); - return ret; + +done: + return ret < 0 ? ret : size; } static const struct misc_ops rockchip_efuse_ops = { -- 2.40.0