Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2904317imm; Fri, 19 Oct 2018 01:30:54 -0700 (PDT) X-Google-Smtp-Source: ACcGV60HDCGEmY5zeDun+dQwZHQvF6qRCzWb9PYzHm1uR4u6DkKdAw9wl0eMTP0f764Q8P5Iyjnd X-Received: by 2002:a63:700e:: with SMTP id l14-v6mr30759914pgc.359.1539937854520; Fri, 19 Oct 2018 01:30:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539937854; cv=none; d=google.com; s=arc-20160816; b=DsRQp/7jz7CXtY6kaA6V16TM8xJiyORjp8/oVhSwD/iSn6gUIkIZo45Ybo3och/rZc G/5KRHK8yALbY7/8yLIf3d3cP2UIHoVEulX8rKUqrEwoAGnrN2ULb4r7WmZcCCGTvAfZ Pn84t9zV3TNWGNXP3DxHhOD8uzzV9DrqYWUV/spim2zTAPBT8QyTD1UDJG6N/ITGnm2G ki7eUBLXYUlSb9XOMnoDt36nYZETNG/sXFs9/ViEWMgviLXxVVvesbOytOiCwxRORcKF +nXrIqm8koQVxB/8ibhwV0V3ICdR6VrTK7VVYdHbh8ZfauaAH1lRkqWIO74Q2p4UChfU z8Mw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=/WNejpCJP4pns22ssPOMk2AZM8A6MMWKQJ57jz8ZzHQ=; b=i3Xsxwcknc4ODZbKA4U/eVmtwGDBRn0mYogtiqaH1YJ0jRowy0kw3GXFR3xgo/MusE 0qvzy/BlzT2dO1FRq74b7Da09QX5yuXlUSBWpZ73mhOgMecXPZo2S30kM1NaT2QB3l9C HbdfXP5mcoMrNQMn149Hbjm8G1EJ5bsmRsjen/lja3bKUeOmMHX+7fiRre0rpcwVtJ/b 3l6+WNwcQVuMe5gxIQMPnYOCUUcuaMsv6ROUxsYgF76Ne8q/aXcoaLwLAOdqhEb4qrf7 Ypniv+HmB7tqiLxz9soaorInP8hlmKvQhp7htbSVcZbxp+uRAZYzaPquAP1A1wxwx3I3 SQPg== 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 a16-v6si22057107pgw.187.2018.10.19.01.30.38; Fri, 19 Oct 2018 01:30:54 -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 S1727049AbeJSQex (ORCPT + 99 others); Fri, 19 Oct 2018 12:34:53 -0400 Received: from mail-sz2.amlogic.com ([211.162.65.114]:61290 "EHLO mail-sz2.amlogic.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726609AbeJSQex (ORCPT ); Fri, 19 Oct 2018 12:34:53 -0400 Received: from [10.28.18.51] (10.28.18.51) by mail-sz2.amlogic.com (10.28.11.6) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Fri, 19 Oct 2018 16:29:39 +0800 Subject: Re: [PATCH v5 2/2] mtd: rawnand: meson: add support for Amlogic NAND flash controller To: Boris Brezillon , Jianxin Pan CC: , 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 , , , References: <1539839345-14021-1-git-send-email-jianxin.pan@amlogic.com> <1539839345-14021-3-git-send-email-jianxin.pan@amlogic.com> <20181018225009.59d94aee@bbrezillon> From: Liang Yang Message-ID: <695f6a8b-d37b-bc57-215b-eb6c36252a80@amlogic.com> Date: Fri, 19 Oct 2018 16:29:40 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181018225009.59d94aee@bbrezillon> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.28.18.51] X-ClientProxiedBy: mail-sz2.amlogic.com (10.28.11.6) To mail-sz2.amlogic.com (10.28.11.6) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/10/19 4:50, Boris Brezillon wrote: > 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? > when calling read_oob or write_oob, i need a mid-buffer which is used in meson_nfc_prase_data_oob(). i.e. after reading a page data into nfc->data_buf, I will format it and transfer to chip->data_buf. >> + 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. > ok, i will move it in the chip struct . but how memleak happens even i have called meson_nfc_free_buffer before and free data_buf if info_buf alloc faied. >> + >> + return 0; >> +} > > . >