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: 1879315 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=UhRVPOij; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Qhxj33QJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SwyHl05D2z1ySd for ; Fri, 22 Dec 2023 04:35:14 +1100 (AEDT) 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=vVZ2hgakljheu/5sjOP0jf/6e6kch87PjGfcbeHiYDo=; b=UhRVPOijMrZ1IB 0fprg3js7cH8HZxHLu+en+kTSHSbYoaBTPkVxtV8BNKWcKr7ZStSn4JTGnizp7sNakENJ0Njgtwj6 wZjpxApCIZ/aNqbRpdwPWrxqKSNH8kxhkDNF1OdWIxgY/Bj4CoYGcyMxOQrZls/kJ6UXxgIa1sBh0 pxNZhzK8sVHlRuW7SIO0iUR/QDH/DXyOUcYDlyDn4kGFSbLrXi06kWeFW0aONPv1g0nnLEdwj8Zr1 6FczUPEwXVwJ60ay6o5vz6cBTnp1nzsPJtWOxcIPQqMhyEaURBjkRgHdrCYFemGLvEwxadTygep6Y DDdMuXqFJQZnxfa6axyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rGMwa-003g9E-14; Thu, 21 Dec 2023 17:34:48 +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-Spam-Score: 0.1 (/) X-Spam-Report: =?unknown-8bit?q?Spam_detection_software=2C_running_on_the_sy?= =?unknown-8bit?q?stem_=22bombadil=2Einfradead=2Eorg=22=2C?= =?unknown-8bit?q?_has_NOT_identified_this_incoming_email_as_spam=2E__The_ori?= =?unknown-8bit?q?ginal?= =?unknown-8bit?q?_message_has_been_attached_to_this_so_you_can_view_it_or_la?= =?unknown-8bit?q?bel?= =?unknown-8bit?q?_similar_future_email=2E__If_you_have_any_questions=2C_see?= =?unknown-8bit?q?_the_administrator_of_that_system_for_details=2E?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_preview=3A__From=3A_Rafa=C5=82_Mi=C5=82ecki_Use_nv?= =?unknown-8bit?q?mem=5Fdev=5Fsize=28=29_and_nvmem=5Fdevice=5Fread=28=29?= =?unknown-8bit?q?_to_make_this_driver_less_mtd_dependent=2E_Signed-off-by=3A?= =?unknown-8bit?q?_Rafa=C5=82_Mi=C5=82ecki_Reviewed-by=3A?= =?unknown-8bit?q?_Miquel_Raynal_---_V2=3A_Don=27t_introduce_memleak_when_han?= =?unknown-8bit?q?dling_nvmem=5Fdevice=5Fread=28=29?= =?unknown-8bit?q?_failures_V3=3A_Split_PATCH_3/3_into_two_?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_analysis_details=3A___=280=2E1_points=2C_5=2E0_req?= =?unknown-8bit?q?uired=29?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_pts_rule_name______________description?= =?unknown-8bit?q?_----_----------------------_------------------------------?= =?unknown-8bit?q?--------------------?= =?unknown-8bit?q?_-0=2E0_RCVD=5FIN=5FDNSWL=5FNONE_____RBL=3A_Sender_listed_a?= =?unknown-8bit?q?t_https=3A//www=2Ednswl=2Eorg/=2C?= =?unknown-8bit?q?_no_trust?= =?unknown-8bit?b?IFsyYTAwOjE0NTA6NDg2NDoyMDowOjA6MDo1MzYgbGlzdGVkIGluXQ==?= =?unknown-8bit?b?IFtsaXN0LmRuc3dsLm9yZ10=?= =?unknown-8bit?q?_-0=2E0_SPF=5FPASS_______________SPF=3A_sender_matches_SPF_?= =?unknown-8bit?q?record?= =?unknown-8bit?q?_0=2E0_SPF=5FHELO=5FNONE__________SPF=3A_HELO_does_not_publ?= =?unknown-8bit?q?ish_an_SPF_Record?= =?unknown-8bit?q?_0=2E0_FREEMAIL=5FFROM__________Sender_email_is_commonly_ab?= =?unknown-8bit?q?used_enduser_mail?= =?unknown-8bit?q?_provider?= =?unknown-8bit?q?_=5Bzajec5=5Bat=5Dgmail=2Ecom=5D?= =?unknown-8bit?q?_0=2E2_FREEMAIL=5FENVFROM=5FEND=5FDIGIT_Envelope-from_freem?= =?unknown-8bit?q?ail_username_ends?= =?unknown-8bit?q?_in_digit?= =?unknown-8bit?q?_=5Bzajec5=5Bat=5Dgmail=2Ecom=5D?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID=5FAU__________Message_has_a_valid_DKIM?= =?unknown-8bit?q?_or_DK_signature_from?= =?unknown-8bit?q?_author=27s_domain?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID_____________Message_has_at_least_one_v?= =?unknown-8bit?q?alid_DKIM_or_DK_signature?= =?unknown-8bit?q?_0=2E1_DKIM=5FSIGNED____________Message_has_a_DKIM_or_DK_si?= =?unknown-8bit?q?gnature=2C_not_necessarily?= =?unknown-8bit?q?_valid?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID=5FEF__________Message_has_a_valid_DKIM?= =?unknown-8bit?q?_or_DK_signature_from?= =?unknown-8bit?q?_envelope-from_domain?= X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.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);