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 5AE64C76195 for ; Mon, 27 Mar 2023 11:01:57 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D99C685D13; Mon, 27 Mar 2023 13:01:34 +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="B5WaXAhF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 666A185D13; Mon, 27 Mar 2023 13:01:25 +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 DDFCA85D3A 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=wriLua2dDKyifNrUtktYHf1Vn0Vq6YMSwnRB+Ntk2qg=; b=B5WaXAhF/WVZz14l3RIYuK+9zt m/CzUPGPd3Q1JaHJyFNfSR+iXCOW75hi1Xpq28xzB1qB9z4LRZic4gyvCz9Q4Kiayu7q+OU/kbuSs GSH5foKrIfLnYCukApZHpVyrDIzBh/D7ZCEghVNus66QViMl4HIQVCq4Axvyp3/8iCbCHCo8lXY1w zPsG9+3EgB9tohiSO/6Ep1TjPviBfdozQ3PlmgBGF1GHOd26fgdpcwQk4yee4rw1mUNlfoB8Y4Qgv ytvQpj/3IJ+QsJl+5CknAV71UGAlkBFcpAtNqCxhdOzd2pCFev6cFRo8vQZr0so2B080/jqpqHAvJ JPJwEmbQ==; 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 1pgkbG-00079X-2j; 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 3/3] rockchip: otp: fix misc_read() return values Date: Mon, 27 Mar 2023 12:01:10 +0100 Message-Id: <20230327110110.1312992-4-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: new patch drivers/misc/rockchip-otp.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/misc/rockchip-otp.c b/drivers/misc/rockchip-otp.c index c19cd5ce62..4814e0e501 100644 --- a/drivers/misc/rockchip-otp.c +++ b/drivers/misc/rockchip-otp.c @@ -89,7 +89,7 @@ static int dump_otp(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)); @@ -249,8 +249,10 @@ static int rockchip_otp_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; @@ -266,7 +268,9 @@ static int rockchip_otp_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_otp_ops = { -- 2.40.0