From patchwork Thu Dec 21 17:34:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 13502449 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6414EC35274 for ; Thu, 21 Dec 2023 17:35:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tgK6uc8sDSLbXxPFCo5N+iEjbPM0MYNwZGo1wY3z0nc=; b=KqUg4IWb25G0Rn m88Z52zMkB/BQ9O6x8WxvePoDkE2VtEz0CS7wU8kZFs2PARJBDppyIXizP8mKaCKxncvDxkf7Xa4y oSnEvus5YJ2tbQST44LCCVukv24I6kiez8ovQnKlFs0rzNDTknhgOZxyTWZ8TJ5TnDcKjKWzF17Km 2ehO9yBEjlTgnZLfD+xkrFA7DMNcdb8ETRu8TwLGxRxUyuoIS8Oqa4hRayjQbFqcxJIL3bH6XrkPg ngLQjpHl0ZDBCPE8RfnVlRG15iI0UZ4MeV+laRWOG2VRtCiugE9IWXC59qD4Ede3buzfQOL/TB8xq FhNG6ODL8X4dzMk9S1iQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rGMwg-003gDU-2y; Thu, 21 Dec 2023 17:34:54 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rGMwS-003g2t-28; Thu, 21 Dec 2023 17:34:42 +0000 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5534d8fcf7bso1263553a12.3; Thu, 21 Dec 2023 09:34:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703180077; x=1703784877; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uejKEmqNBQrYztiORMBuyN6ikCtupKPpOgESMooLig8=; b=Qhxj33QJ9IOYJylBWAHC5Q/Qng0h5I1MswEVsxLrJZ2xM4LGDzXl8ljE9aCVFoZHYW dOstXzwJ//c6r5rVZ++r6XdCWOEX6NC//N8pIjeJ+jlTCDIOWXNDMLI14Sc4trP2ofcQ BUqmZB9tbruuvMgIV+WbcGfbwodZQpBs0MTAeDNECmmD+1gzgZdu7cE/JtpYF61B7rhD ocyunDun0FSQb6YYgvu3TVQwIH1W4vbbik7WNByUd3XBlYIvyxuuiW/x4O/hxrOruAro kjKCmN/9stjcBQ7WX7nunYIH4gCmVAp2l/+PDQJQ1BCxsIDNWyNVrQLhpUBdVxmNuWXM Gyog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703180077; x=1703784877; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uejKEmqNBQrYztiORMBuyN6ikCtupKPpOgESMooLig8=; b=eR4dJSz8uBoC/fKHqok85e/aTJyCFP1s175zmGeIwdGqKUz/woKfxEpTmGYeFM6Jnc y1uk+XcbMWe3cZCJgQguAvxYqKrdenc2Lks8jMqmZn+MfjAS6jKHykWuvujlTYucmVmz C1sFyn2ldAmK4xiUrnFfXBgnSnVdWiA8WxSh7RGS/axZQu6vnRBffirn+PyZWOGoqJG2 Clg33HutzXSediaXIl+chLPu8zNHt/rckev/0ZKUQopSvdRLZTauv8/sNAXl0Pn7O+qi 01EljRahWQgKyDMFYdeeFt4GX+yKFZvLH+XodwDDywrnyQBgiJAt3c+G67hhgyIJvj7u 1a6w== X-Gm-Message-State: AOJu0Yw+k/NgKSjS5ZLcRUMnDEosNGJmJ6tLvTCv5HZdKxmmXrGDLuFZ EpaADQwE7XmYEgpFz3I9h58= X-Google-Smtp-Source: AGHT+IHBM2cuaZaaA6HZDolSKAmB6b+hcQMYNNQNKu4rhLvbzqoo/2RVerHBx7krYnQ1piWwRFQhkw== X-Received: by 2002:a17:906:29cf:b0:a23:8a00:cfbe with SMTP id y15-20020a17090629cf00b00a238a00cfbemr73085eje.132.1703180077492; Thu, 21 Dec 2023 09:34:37 -0800 (PST) Received: from localhost.lan (031011218106.poznan.vectranet.pl. [31.11.218.106]) by smtp.gmail.com with ESMTPSA id z25-20020a1709060ad900b00a23499f1d7dsm1176118ejf.209.2023.12.21.09.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 09:34:37 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Greg Kroah-Hartman , Michael Walle , Miquel Raynal , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, u-boot@lists.denx.de, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V3 4/6] nvmem: u-boot-env: use nvmem device helpers Date: Thu, 21 Dec 2023 18:34:19 +0100 Message-Id: <20231221173421.13737-4-zajec5@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231221173421.13737-1-zajec5@gmail.com> References: <20231221173421.13737-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231221_093440_723233_BBF9475F X-CRM114-Status: GOOD ( 14.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Rafał Miłecki Use nvmem_dev_size() and nvmem_device_read() to make this driver less mtd dependent. Signed-off-by: Rafał Miłecki Reviewed-by: Miquel Raynal --- V2: Don't introduce memleak when handling nvmem_device_read() failures V3: Split PATCH 3/3 into two drivers/nvmem/u-boot-env.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c index dd9d0ad22712..111905189341 100644 --- a/drivers/nvmem/u-boot-env.c +++ b/drivers/nvmem/u-boot-env.c @@ -127,27 +127,34 @@ static int u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf, static int u_boot_env_parse(struct u_boot_env *priv) { + struct nvmem_device *nvmem = priv->nvmem; struct device *dev = priv->dev; size_t crc32_data_offset; size_t crc32_data_len; size_t crc32_offset; size_t data_offset; size_t data_len; + size_t dev_size; uint32_t crc32; uint32_t calc; - size_t bytes; uint8_t *buf; + int bytes; int err; - buf = kcalloc(1, priv->mtd->size, GFP_KERNEL); + dev_size = nvmem_dev_size(nvmem); + + buf = kcalloc(1, dev_size, GFP_KERNEL); if (!buf) { err = -ENOMEM; goto err_out; } - err = mtd_read(priv->mtd, 0, priv->mtd->size, &bytes, buf); - if ((err && !mtd_is_bitflip(err)) || bytes != priv->mtd->size) { - dev_err(dev, "Failed to read from mtd: %d\n", err); + bytes = nvmem_device_read(nvmem, 0, dev_size, buf); + if (bytes < 0) { + err = bytes; + goto err_kfree; + } else if (bytes != dev_size) { + err = -EIO; goto err_kfree; } @@ -169,8 +176,8 @@ static int u_boot_env_parse(struct u_boot_env *priv) break; } crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset)); - crc32_data_len = priv->mtd->size - crc32_data_offset; - data_len = priv->mtd->size - data_offset; + crc32_data_len = dev_size - crc32_data_offset; + data_len = dev_size - data_offset; calc = crc32(~0, buf + crc32_data_offset, crc32_data_len) ^ ~0L; if (calc != crc32) { @@ -179,7 +186,7 @@ static int u_boot_env_parse(struct u_boot_env *priv) goto err_kfree; } - buf[priv->mtd->size - 1] = '\0'; + buf[dev_size - 1] = '\0'; err = u_boot_env_add_cells(priv, buf, data_offset, data_len); if (err) dev_err(dev, "Failed to add cells: %d\n", err);