Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4688882imm; Sun, 22 Jul 2018 03:35:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcw7s/9eQNkFMWw1J0wlN6xFD6hpeFuTtNz+MRUywNeyC4L/1ji8x9Cf16G55JeWtJNnTQO X-Received: by 2002:a17:902:7446:: with SMTP id e6-v6mr8813685plt.161.1532255714795; Sun, 22 Jul 2018 03:35:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532255714; cv=none; d=google.com; s=arc-20160816; b=HxHbdnH18K64MmzQmHiGpEFDzlwxVoErzrOiK8L5NJjE3/GXseLiDdMKrUu5mlt0fn Fs+wKn6eMNHtsleIPLNsT2fnLEikeAaW/T7xRN3UvZU3vdXjg6t16MpybxNZMEB1c96l IRArwKeRYxh0zdh+4BV9JR7HHbM5ZnMuu/UuViBStCGDcvWAiBCjtfGOwU8rmHcb2wcs eH4RnC3fzVGCS6220L/7c13ABdBojvVkv/Bd4eAL6mf9JZJCyAXsSIBCZcWX/83gahOZ vIG5Y+PVp/D5TRUg6OUL6VWEWSsSLs6Adtw/Y14N+r4iBqMxkHl/IUw9r/P6bk2MrKEf 699A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=GS/TV5oW7Eyca9PKdgYwh89eok7lyvoFMZ6NhgeqobY=; b=KKgHZF1QkjsC+0cPZjQ0R/UxWYpIqxKfMWBRR+8a3cqDQeECQl9WmbVjCgiumkm4Y0 SSJug1lXUSRgE1g69s5H7iGLRN5tlRjMgfAD2QA3MI/lcOya3dklOPXMSkfjxlggZnj1 jc5vz5KJ/BQ7AvgFN/a8uIbygLF9yCOWAKA3SxTrfrJbLHUDIi/L8WrwOgobUHUAk/yc QKUfKduZETTYZis8RVRvOQ7VZAd0JL3QY5817FNRzyzu0uo6w+whnictUoeRGbrmJKQD MF+yOvfyia65wpHkPjFKSY+PzTP3gCyZ61vRB2ZGFL1WTtot+bLJWsQf1uFcsSQrncJ4 k45w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l13-v6si6161898pgr.291.2018.07.22.03.35.00; Sun, 22 Jul 2018 03:35:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728336AbeGVL2w (ORCPT + 99 others); Sun, 22 Jul 2018 07:28:52 -0400 Received: from mail.bootlin.com ([62.4.15.54]:60145 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727986AbeGVL2v (ORCPT ); Sun, 22 Jul 2018 07:28:51 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id A0E42207B4; Sun, 22 Jul 2018 12:32:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (unknown [37.173.49.123]) by mail.bootlin.com (Postfix) with ESMTPSA id 8A84920717; Sun, 22 Jul 2018 12:32:33 +0200 (CEST) Date: Sun, 22 Jul 2018 12:32:31 +0200 From: Boris Brezillon To: Miquel Raynal Cc: Wenyou Yang , Josh Wu , Tudor Ambarus , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Nicolas Ferre , Alexandre Belloni , Kamal Dasu , Masahiro Yamada , Han Xu , Harvey Hunt , Vladimir Zapolskiy , Sylvain Lemieux , Xiaolei Li , Matthias Brugger , Maxime Ripard , Chen-Yu Tsai , Marc Gonzalez , Mans Rullgard , Stefan Agner , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-mediatek@lists.infradead.org Subject: Re: [PATCH v4 34/35] mtd: rawnand: allocate model parameter dynamically Message-ID: <20180722123231.1cde7180@bbrezillon> In-Reply-To: <20180720151527.16038-35-miquel.raynal@bootlin.com> References: <20180720151527.16038-1-miquel.raynal@bootlin.com> <20180720151527.16038-35-miquel.raynal@bootlin.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 20 Jul 2018 17:15:26 +0200 Miquel Raynal wrote: > Thanks to the migration of all drivers to use nand_scan() and the > related nand_controller_ops, we can now allocate data during the > detection phase. Let's do it first for the NAND model parameter which > is allocated in nand_detect(). > > Signed-off-by: Miquel Raynal Reviewed-by: Boris Brezillon > --- > drivers/mtd/nand/raw/nand_base.c | 52 +++++++++++++++++++++++++++++++--------- > include/linux/mtd/rawnand.h | 2 +- > 2 files changed, 42 insertions(+), 12 deletions(-) > > diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c > index da99232702a4..8645f655e5b0 100644 > --- a/drivers/mtd/nand/raw/nand_base.c > +++ b/drivers/mtd/nand/raw/nand_base.c > @@ -5225,8 +5225,11 @@ static int nand_flash_detect_onfi(struct nand_chip *chip) > > sanitize_string(p->manufacturer, sizeof(p->manufacturer)); > sanitize_string(p->model, sizeof(p->model)); > - strncpy(chip->parameters.model, p->model, > - sizeof(chip->parameters.model) - 1); > + chip->parameters.model = kstrdup(p->model, GFP_KERNEL); > + if (!chip->parameters.model) { > + ret = -ENOMEM; > + goto free_onfi_param_page; > + } > > mtd->writesize = le32_to_cpu(p->byte_per_page); > > @@ -5356,8 +5359,11 @@ static int nand_flash_detect_jedec(struct nand_chip *chip) > > sanitize_string(p->manufacturer, sizeof(p->manufacturer)); > sanitize_string(p->model, sizeof(p->model)); > - strncpy(chip->parameters.model, p->model, > - sizeof(chip->parameters.model) - 1); > + chip->parameters.model = kstrdup(p->model, GFP_KERNEL); > + if (!chip->parameters.model) { > + ret = -ENOMEM; > + goto free_jedec_param_page; > + } > > mtd->writesize = le32_to_cpu(p->byte_per_page); > > @@ -5546,8 +5552,9 @@ static bool find_full_id_nand(struct nand_chip *chip, > chip->onfi_timing_mode_default = > type->onfi_timing_mode_default; > > - strncpy(chip->parameters.model, type->name, > - sizeof(chip->parameters.model) - 1); > + chip->parameters.model = kstrdup(type->name, GFP_KERNEL); > + if (!chip->parameters.model) > + return false; > > return true; > } > @@ -5706,8 +5713,9 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type) > if (!type->name) > return -ENODEV; > > - strncpy(chip->parameters.model, type->name, > - sizeof(chip->parameters.model) - 1); > + chip->parameters.model = kstrdup(type->name, GFP_KERNEL); > + if (!chip->parameters.model) > + return -ENOMEM; > > chip->chipsize = (uint64_t)type->chipsize << 20; > > @@ -5737,7 +5745,9 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type) > mtd->name); > pr_warn("bus width %d instead of %d bits\n", busw ? 16 : 8, > (chip->options & NAND_BUSWIDTH_16) ? 16 : 8); > - return -EINVAL; > + ret = -EINVAL; > + > + goto free_detect_allocation; > } > > nand_decode_bbm_options(chip); > @@ -5774,6 +5784,11 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type) > (int)(chip->chipsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC", > mtd->erasesize >> 10, mtd->writesize, mtd->oobsize); > return 0; > + > +free_detect_allocation: > + kfree(chip->parameters.model); > + > + return ret; > } > > static const char * const nand_ecc_modes[] = { > @@ -6021,6 +6036,11 @@ static int nand_scan_ident(struct mtd_info *mtd, int maxchips, > return 0; > } > > +static void nand_scan_ident_cleanup(struct nand_chip *chip) > +{ > + kfree(chip->parameters.model); > +} > + > static int nand_set_ecc_soft_ops(struct mtd_info *mtd) > { > struct nand_chip *chip = mtd_to_nand(mtd); > @@ -6764,11 +6784,18 @@ int nand_scan_with_ids(struct mtd_info *mtd, int maxchips, > > ret = nand_attach(chip); > if (ret) > - return ret; > + goto cleanup_ident; > > ret = nand_scan_tail(mtd); > if (ret) > - nand_detach(chip); > + goto detach_chip; > + > + return 0; > + > +detach_chip: > + nand_detach(chip); > +cleanup_ident: > + nand_scan_ident_cleanup(chip); > > return ret; > } > @@ -6800,6 +6827,9 @@ void nand_cleanup(struct nand_chip *chip) > > /* Free controller specific allocations after chip identification */ > nand_detach(chip); > + > + /* Free identification phase allocations */ > + nand_scan_ident_cleanup(chip); > } > > EXPORT_SYMBOL_GPL(nand_cleanup); > diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h > index a928771a7ae4..5723d940a47d 100644 > --- a/include/linux/mtd/rawnand.h > +++ b/include/linux/mtd/rawnand.h > @@ -482,7 +482,7 @@ struct onfi_params { > */ > struct nand_parameters { > /* Generic parameters */ > - char model[100]; > + const char *model; > bool supports_set_get_features; > DECLARE_BITMAP(set_feature_list, ONFI_FEATURE_NUMBER); > DECLARE_BITMAP(get_feature_list, ONFI_FEATURE_NUMBER);