From nobody Thu Apr 9 11:51:26 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C86A2C636CC for ; Sat, 4 Feb 2023 14:36:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233656AbjBDOgF (ORCPT ); Sat, 4 Feb 2023 09:36:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233866AbjBDOfo (ORCPT ); Sat, 4 Feb 2023 09:35:44 -0500 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71E46303D4 for ; Sat, 4 Feb 2023 06:35:20 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id C3EDA5C012A; Sat, 4 Feb 2023 09:35:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sat, 04 Feb 2023 09:35:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1675521319; x=1675607719; bh=z8 +r2WBFXUDnilpI4tJA/upCWvhtMve9E2bc0bx/InM=; b=BzP7c34VyWpM+TWZLt kWCITqpGjiDjHHl9cvQk+awGK4TbfJY3CJUMtNTU7vFA/qqEQJisyHd0mlSgI8Se M4X4YRgUlck5wtn63OdIE6uv4APVG5Ky5N7iS8NuncAd8zpGkvv2Xc+KAm3mgtK9 wJaTSVNwPfwbSk8V0qJoNT8GMn9ZtgRvR7yN/MDb0RAij03j2msCBRNXSMTG1jxT qvUSzW3wL5YWkng35n+r1y6fpDOCkuPzqgiRq6mgV9459/aldVHspxQ8nqKSncfY iD6w51/18Frmmz0hVQPiWSakdBPG755WMxk4a5I69umHJx2e0lg8y9U5427GAo1J LgAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1675521319; x=1675607719; bh=z8+r2WBFXUDni lpI4tJA/upCWvhtMve9E2bc0bx/InM=; b=eVxxNR24iCwEyy7vPhoQR0TBUeS44 BYZp4hTfsQ6EWpQBdKtPyYtfLiIaH+XGAbpP5guCcHb3HLIo1P+XgSR474GVjIbt /meB13cH89phgFXQMJKcztjvYofH6hLPeAiiulwGUHgqnIMhD88XfzOlFZDCvIJk VsbRkXhUGuveTBfuP0+/OJeHWMbgYoYpTihZNkCZTykwJaKf7RhAAKmsIlvdHz7O GNwMR+vegwMSi2qZx4qGnxrA5URsYlIwK1Wb1W90zSSM/JhZ1J3+5tcT3aGNhwCa HCL3oQ42EYN2vThwclHLm3Nrr4kWpm3Snd0npHVEbiBIuLMfDv3lgr9WQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudegvddgieeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepufgrmhhu vghlucfjohhllhgrnhguuceoshgrmhhuvghlsehshhholhhlrghnugdrohhrgheqnecugg ftrfgrthhtvghrnhepudekteeuudehtdelteevgfduvddvjefhfedulefgudevgeeghefg udefiedtveetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepshgrmhhuvghlsehshhholhhlrghnugdrohhrgh X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 4 Feb 2023 09:35:19 -0500 (EST) From: Samuel Holland To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Boris Brezillon , Jernej Skrabec , Chen-Yu Tsai , Samuel Holland , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH v2 2/3] mtd: rawnand: sunxi: Embed sunxi_nand_hw_ecc by value Date: Sat, 4 Feb 2023 08:35:19 -0600 Message-Id: <20230204143520.9682-3-samuel@sholland.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20230204143520.9682-1-samuel@sholland.org> References: <20230204143520.9682-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The sunxi_nand_hw_ecc object is not shared, and it has the same lifetime as the sunxi_nand_chip which points to it, so we can embed it in the outer structure instead of using a pointer. This removes an unnecessary memory allocation and simplifies the error handling code. Signed-off-by: Samuel Holland --- Changes in v2: - Keep `struct sunxi_nand_hw_ecc` but change the pointer to a value - New patch for v2 drivers/mtd/nand/raw/sunxi_nand.c | 45 +++++-------------------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 3c32d31f20aa..a0d0cb17c150 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -193,7 +193,7 @@ struct sunxi_nand_hw_ecc { struct sunxi_nand_chip { struct list_head node; struct nand_chip nand; - struct sunxi_nand_hw_ecc *ecc; + struct sunxi_nand_hw_ecc ecc; unsigned long clk_rate; u32 timing_cfg; u32 timing_ctl; @@ -694,7 +694,7 @@ static void sunxi_nfc_hw_ecc_enable(struct nand_chip *n= and) ecc_ctl =3D readl(nfc->regs + NFC_REG_ECC_CTL); ecc_ctl &=3D ~(NFC_ECC_MODE_MSK | NFC_ECC_PIPELINE | NFC_ECC_BLOCK_SIZE_MSK); - ecc_ctl |=3D NFC_ECC_EN | NFC_ECC_MODE(sunxi_nand->ecc->mode) | + ecc_ctl |=3D NFC_ECC_EN | NFC_ECC_MODE(sunxi_nand->ecc.mode) | NFC_ECC_EXCEPTION | NFC_ECC_PIPELINE; =20 if (nand->ecc.size =3D=3D 512) @@ -1626,11 +1626,6 @@ static const struct mtd_ooblayout_ops sunxi_nand_oob= layout_ops =3D { .free =3D sunxi_nand_ooblayout_free, }; =20 -static void sunxi_nand_hw_ecc_ctrl_cleanup(struct sunxi_nand_chip *sunxi_n= and) -{ - kfree(sunxi_nand->ecc); -} - static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, struct nand_ecc_ctrl *ecc, struct device_node *np) @@ -1641,7 +1636,6 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_ch= ip *nand, struct mtd_info *mtd =3D nand_to_mtd(nand); struct nand_device *nanddev =3D mtd_to_nanddev(mtd); int nsectors; - int ret; int i; =20 if (nanddev->ecc.user_conf.flags & NAND_ECC_MAXIMIZE_STRENGTH) { @@ -1676,10 +1670,6 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_c= hip *nand, if (ecc->size !=3D 512 && ecc->size !=3D 1024) return -EINVAL; =20 - sunxi_nand->ecc =3D kzalloc(sizeof(*sunxi_nand->ecc), GFP_KERNEL); - if (!sunxi_nand->ecc) - return -ENOMEM; - /* Prefer 1k ECC chunk over 512 ones */ if (ecc->size =3D=3D 512 && mtd->writesize > 512) { ecc->size =3D 1024; @@ -1700,11 +1690,10 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_= chip *nand, =20 if (i >=3D ARRAY_SIZE(strengths)) { dev_err(nfc->dev, "unsupported strength\n"); - ret =3D -ENOTSUPP; - goto err; + return -ENOTSUPP; } =20 - sunxi_nand->ecc->mode =3D i; + sunxi_nand->ecc.mode =3D i; =20 /* HW ECC always request ECC bytes for 1024 bytes blocks */ ecc->bytes =3D DIV_ROUND_UP(ecc->strength * fls(8 * 1024), 8); @@ -1714,10 +1703,8 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_c= hip *nand, =20 nsectors =3D mtd->writesize / ecc->size; =20 - if (mtd->oobsize < ((ecc->bytes + 4) * nsectors)) { - ret =3D -EINVAL; - goto err; - } + if (mtd->oobsize < ((ecc->bytes + 4) * nsectors)) + return -EINVAL; =20 ecc->read_oob =3D sunxi_nfc_hw_ecc_read_oob; ecc->write_oob =3D sunxi_nfc_hw_ecc_write_oob; @@ -1740,25 +1727,6 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_c= hip *nand, ecc->write_oob_raw =3D nand_write_oob_std; =20 return 0; - -err: - kfree(sunxi_nand->ecc); - - return ret; -} - -static void sunxi_nand_ecc_cleanup(struct sunxi_nand_chip *sunxi_nand) -{ - struct nand_ecc_ctrl *ecc =3D &sunxi_nand->nand.ecc; - - switch (ecc->engine_type) { - case NAND_ECC_ENGINE_TYPE_ON_HOST: - sunxi_nand_hw_ecc_ctrl_cleanup(sunxi_nand); - break; - case NAND_ECC_ENGINE_TYPE_NONE: - default: - break; - } } =20 static int sunxi_nand_attach_chip(struct nand_chip *nand) @@ -1971,7 +1939,6 @@ static void sunxi_nand_chips_cleanup(struct sunxi_nfc= *nfc) ret =3D mtd_device_unregister(nand_to_mtd(chip)); WARN_ON(ret); nand_cleanup(chip); - sunxi_nand_ecc_cleanup(sunxi_nand); list_del(&sunxi_nand->node); } } --=20 2.37.4