From patchwork Sat Feb 4 14:35:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 52786 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1377384wrn; Sat, 4 Feb 2023 06:39:38 -0800 (PST) X-Google-Smtp-Source: AK7set9SAmMq5TRCY+8Ck9TC1GdDleFmaV18CRhBWJMsbnncMCLOaOwHkIhInKEHriO2zDoHmz+r X-Received: by 2002:a17:906:99d0:b0:88c:4f0d:85ac with SMTP id s16-20020a17090699d000b0088c4f0d85acmr14786123ejn.77.1675521578097; Sat, 04 Feb 2023 06:39:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675521578; cv=none; d=google.com; s=arc-20160816; b=rMJwtN4CC/bTznP/+QSqITP/pHeKl26uk/1RuRfuUYtJwO55hciNvD5nhyyOFhdq65 R2xx29yVuLPh6zT0jbXHvVihEOULtJXGGlK1TKaSbYlgD2wldeUz+MFZa4foIFpVguGU acsHJOPtaHRdnn+kFBhuYQZGGSAFvZ3ODkHkqL5lSrgZKLarRiwiTo7bdBWGX+fTJUtX Cq4AeL+Ouoe2WNW/GIRCmF+O9S6KQBobaXLuYtYqwqVoaHmPf5t72VYo83F06aMebeER dWrTDZdrvdJh610cWpyUNNj5C36ZyarSTRQFvZtxbY2fSujrq910wSUTjjVQuuX72AA6 irgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=z8+r2WBFXUDnilpI4tJA/upCWvhtMve9E2bc0bx/InM=; b=mpyR3Jm1Tq1vyO6cN3HeYpKd1q6lVG9HizO+iCxiJur6ClV/c4OQBJaJ9gj1ird11W p6oxchWs49q+/7jbxKpc9A19b4Kn/MoQhxn9vTsFFjmb+89PSbIiepP/LlP+dvKsEdxN YAV1c3soILT0cGKmBBPALF4mzfDYLNgd7ZX+4aiicawrdKp2hwjZNUEbWtn5TcccOxTY UnxjTWojzjzvyp1KJIgqfsXKk+WIV8ciPR/P6fuHG4OePByz/AtaiQkyIJwtXopnaRe5 xG4+FN6irbzu7R3v3nRX86pPRJXtjNt7Ap+pifdayMFn3leveb//j3eVGU2rBRyUhYG5 4QmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm1 header.b=BzP7c34V; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=eVxxNR24; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sholland.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 29-20020a170906005d00b007c13387a548si7417549ejg.26.2023.02.04.06.39.13; Sat, 04 Feb 2023 06:39:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sholland.org header.s=fm1 header.b=BzP7c34V; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=eVxxNR24; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sholland.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233632AbjBDOgE (ORCPT + 99 others); Sat, 4 Feb 2023 09:36:04 -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 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756911714523388215?= X-GMAIL-MSGID: =?utf-8?q?1756911714523388215?= 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 *nand) ecc_ctl = readl(nfc->regs + NFC_REG_ECC_CTL); ecc_ctl &= ~(NFC_ECC_MODE_MSK | NFC_ECC_PIPELINE | NFC_ECC_BLOCK_SIZE_MSK); - ecc_ctl |= NFC_ECC_EN | NFC_ECC_MODE(sunxi_nand->ecc->mode) | + ecc_ctl |= NFC_ECC_EN | NFC_ECC_MODE(sunxi_nand->ecc.mode) | NFC_ECC_EXCEPTION | NFC_ECC_PIPELINE; if (nand->ecc.size == 512) @@ -1626,11 +1626,6 @@ static const struct mtd_ooblayout_ops sunxi_nand_ooblayout_ops = { .free = sunxi_nand_ooblayout_free, }; -static void sunxi_nand_hw_ecc_ctrl_cleanup(struct sunxi_nand_chip *sunxi_nand) -{ - 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_chip *nand, struct mtd_info *mtd = nand_to_mtd(nand); struct nand_device *nanddev = mtd_to_nanddev(mtd); int nsectors; - int ret; int i; if (nanddev->ecc.user_conf.flags & NAND_ECC_MAXIMIZE_STRENGTH) { @@ -1676,10 +1670,6 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, if (ecc->size != 512 && ecc->size != 1024) return -EINVAL; - sunxi_nand->ecc = kzalloc(sizeof(*sunxi_nand->ecc), GFP_KERNEL); - if (!sunxi_nand->ecc) - return -ENOMEM; - /* Prefer 1k ECC chunk over 512 ones */ if (ecc->size == 512 && mtd->writesize > 512) { ecc->size = 1024; @@ -1700,11 +1690,10 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, if (i >= ARRAY_SIZE(strengths)) { dev_err(nfc->dev, "unsupported strength\n"); - ret = -ENOTSUPP; - goto err; + return -ENOTSUPP; } - sunxi_nand->ecc->mode = i; + sunxi_nand->ecc.mode = i; /* HW ECC always request ECC bytes for 1024 bytes blocks */ ecc->bytes = DIV_ROUND_UP(ecc->strength * fls(8 * 1024), 8); @@ -1714,10 +1703,8 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, nsectors = mtd->writesize / ecc->size; - if (mtd->oobsize < ((ecc->bytes + 4) * nsectors)) { - ret = -EINVAL; - goto err; - } + if (mtd->oobsize < ((ecc->bytes + 4) * nsectors)) + return -EINVAL; ecc->read_oob = sunxi_nfc_hw_ecc_read_oob; ecc->write_oob = sunxi_nfc_hw_ecc_write_oob; @@ -1740,25 +1727,6 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, ecc->write_oob_raw = nand_write_oob_std; 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 = &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; - } } 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 = mtd_device_unregister(nand_to_mtd(chip)); WARN_ON(ret); nand_cleanup(chip); - sunxi_nand_ecc_cleanup(sunxi_nand); list_del(&sunxi_nand->node); } }