Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2389443imm; Thu, 18 Oct 2018 13:53:01 -0700 (PDT) X-Google-Smtp-Source: ACcGV60ZZL1VKv2L/TXpjR4Q74vUuswaZijpCQaPrOLL72JLkW7qLCfJTmZAKGGkGUU6G6fr74RQ X-Received: by 2002:a63:f252:: with SMTP id d18-v6mr30063040pgk.2.1539895981318; Thu, 18 Oct 2018 13:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539895981; cv=none; d=google.com; s=arc-20160816; b=XfIkxvRueljl7Def5EQE7Qs7O4VgdFhjazRwQ7Nwz06kCcUTB6xgZqoIuQug6S+nJZ MbxJDtxC0zDCxJNirC/+7sd4CjPOpIIwqGUCks79qW175c89jEEwsuNQ+DnPEVVrvGWH GAltLxZxsHpZN83mBA3uWC8jdkvubq3bqPFUQixixW2mBfZKiVzpBWjkAFzDdEgAzFuI 24HaWnmRAA9t9Wyy55emjhVqxw3EvHTmxIKbwk3Oj0MhlnGTxQMsPKEJWbR1sLskGqcE +Lxpb38JDMwy7e4q/7+8cQrXM6ObiEvoo4JznH7uE2X8/WwG/OiW9kg6bSOORMWO/P9S 9wpw== 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; bh=4rH3ihvna1iKBBc6sSHtkdrljJgd7pB7V9RjZmgbJV4=; b=JpMNxZdVEj48LJAXu6RKLDsyDQT3mK3hvBJoj0HVE7ZdUaMMVH6ZpNxhImf0VZgXde XH1XixPN/qItEkcBErTpD3ROpVXP6qeo8DgR/38fu+ftsai6KCfr9VfMdSwV9laU1Z9A h4op0RU7cnglLc6djQcXF3ngKCf8h718Mq8YxPeXttXLa54vtzZfU9OpIcSBgDueZYXm bOW8uIjPWNNrpSW7mrYSyK8kJn6YJSybljjY+eelPdtz8DXG5u3TMWkmJ96ABAxxfZC8 MPNxkZvPf1eXN6AsLXQXwK3q6bf7sOe7j9R0+DHcm096ZgBu5Na1CyhTESPgF5TNtNOD Ding== 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 97-v6si21167126plc.30.2018.10.18.13.52.44; Thu, 18 Oct 2018 13:53:01 -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 S1727083AbeJSExL (ORCPT + 99 others); Fri, 19 Oct 2018 00:53:11 -0400 Received: from mail.bootlin.com ([62.4.15.54]:46967 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725738AbeJSExK (ORCPT ); Fri, 19 Oct 2018 00:53:10 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 00C1E20789; Thu, 18 Oct 2018 22:50:20 +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 [91.160.177.164]) by mail.bootlin.com (Postfix) with ESMTPSA id 78F9920723; Thu, 18 Oct 2018 22:50:10 +0200 (CEST) Date: Thu, 18 Oct 2018 22:50:09 +0200 From: Boris Brezillon To: Jianxin Pan Cc: , Liang Yang , Yixun Lan , David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Jerome Brunet , Neil Armstrong , Martin Blumenstingl , Carlo Caione , Kevin Hilman , Rob Herring , Jian Hu , Hanjie Lin , Victor Wan , , , Subject: Re: [PATCH v5 2/2] mtd: rawnand: meson: add support for Amlogic NAND flash controller Message-ID: <20181018225009.59d94aee@bbrezillon> In-Reply-To: <1539839345-14021-3-git-send-email-jianxin.pan@amlogic.com> References: <1539839345-14021-1-git-send-email-jianxin.pan@amlogic.com> <1539839345-14021-3-git-send-email-jianxin.pan@amlogic.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 Thu, 18 Oct 2018 13:09:05 +0800 Jianxin Pan wrote: > +static int meson_nfc_buffer_init(struct mtd_info *mtd) > +{ > + struct nand_chip *nand = mtd_to_nand(mtd); > + struct meson_nfc *nfc = nand_get_controller_data(nand); > + static int max_page_bytes, max_info_bytes; > + int page_bytes, info_bytes; > + int nsectors; > + > + nsectors = mtd->writesize / nand->ecc.size; > + page_bytes = mtd->writesize + mtd->oobsize; > + info_bytes = nsectors * PER_INFO_BYTE; > + > + if (nfc->data_buf && nfc->info_buf) { > + if (max_page_bytes < page_bytes) > + meson_nfc_free_buffer(nfc); > + else > + return 0; > + } > + > + max_page_bytes = max_t(int, max_page_bytes, page_bytes); > + max_info_bytes = max_t(int, max_info_bytes, info_bytes); > + > + nfc->data_buf = kmalloc(max_page_bytes, GFP_KERNEL); Is there a good reason for not using chip->data_buf and allocating a new buffer here? > + if (!nfc->data_buf) > + return -ENOMEM; > + > + nfc->info_buf = kmalloc(max_info_bytes, GFP_KERNEL); > + if (!nfc->info_buf) { > + kfree(nfc->data_buf); > + return -ENOMEM; > + } I'd recommend moving this info_buf in the priv chip struct, otherwise you'll have to protect nfc->info_buf with a lock to prevent an already register chip from using this pointer while you're reallocating the buffer. Also, I think you have a memleak here. > + > + return 0; > +}