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 AA432C76195 for ; Mon, 20 Mar 2023 17:19:04 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 09AD485988; Mon, 20 Mar 2023 18:18:41 +0100 (CET) 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="7LGaiiMk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AACF685B59; Mon, 20 Mar 2023 18:18:34 +0100 (CET) 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 D556985B66 for ; Mon, 20 Mar 2023 18:18:29 +0100 (CET) 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=CNZQFrZDlE1MiDauS9w1QFm1H/dYDPQlCLGOomPJiAs=; b=7LGaiiMkb/6E9ANTBl9YO1SNry qUHNDC0zwlf9amy+6c3PLEqwea7SODcYPcFTOhVyWcfqwyEMcrRNdwxXE/Yvw7bUYhwl1E3BYAGLP INoCh8N4YCYIANvBjcGxYSQpySDNzCJAQM+EfZPOQxHgJZbNg0DNQWO0sCMu3k3vdlzZSy6ZR8vr6 HkCIdfUIMZgH4YfItVH9Co/N41gfzl1qVQDHRBFvE1bUz9qi2Lv6FxxtKZ+v3NvRL+vnjOnCnWnqE +S68JqSx6Yg5yqCwjPnH7r+Ceat5PMC0C4k+8aA2n+ZPNj8fE8deSVGVFflnkVkBO6W5KzceLZZIx Ksijkx3w==; 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 1peJ9O-0003OU-3p; Mon, 20 Mar 2023 17:18:27 +0000 From: John Keeping To: u-boot@lists.denx.de Cc: Simon Glass , Philipp Tomsich , Kever Yang , Jonas Karlman , John Keeping Subject: [PATCH v2 1/2] rockchip: efuse: fix misc_read() return values Date: Mon, 20 Mar 2023 17:18:21 +0000 Message-Id: <20230320171822.1605531-2-john@metanate.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230320171822.1605531-1-john@metanate.com> References: <20230320171822.1605531-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. Signed-off-by: John Keeping --- 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