From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D41CC4338F for ; Tue, 17 Aug 2021 02:46:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E5A160F46 for ; Tue, 17 Aug 2021 02:46:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235740AbhHQCqc (ORCPT ); Mon, 16 Aug 2021 22:46:32 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:14216 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233438AbhHQCqa (ORCPT ); Mon, 16 Aug 2021 22:46:30 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Gpb4G0HlRz1CXd5; Tue, 17 Aug 2021 10:45:34 +0800 (CST) Received: from dggema761-chm.china.huawei.com (10.1.198.203) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Tue, 17 Aug 2021 10:45:56 +0800 Received: from [10.174.178.46] (10.174.178.46) by dggema761-chm.china.huawei.com (10.1.198.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Tue, 17 Aug 2021 10:45:55 +0800 Subject: Re: [PATCH v2] mtd: mtdconcat: Check existence of _read|_write from subdev'master device before assigning To: , , , CC: , , , References: <20210817024552.1691649-1-chengzhihao1@huawei.com> From: Zhihao Cheng Message-ID: <8b315831-84c5-38f3-d3b7-bb53f52c28b8@huawei.com> Date: Tue, 17 Aug 2021 10:45:55 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20210817024552.1691649-1-chengzhihao1@huawei.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.46] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggema761-chm.china.huawei.com (10.1.198.203) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ÔÚ 2021/8/17 10:45, Zhihao Cheng дµÀ: Hi Miquel, I found a better way to fix the "WARNING" on _read|_read_oob checking. Since sub-mtd device has been registered successfully, we can check against the existence of _read|_read_oob callbacks by subdev's master device. BTW, fix missing space between the SHA1 and the subject suggested by Stephen. > Since 2431c4f5b46c3 ("mtd: Implement mtd_{read,write}() as wrappers > around mtd_{read,write}_oob()") don't allow _write|_read and > _write_oob|_read_oob existing at the same time. We should check the > existence of callbacks "_read and _write" from subdev's master device > (We can trust master device since it has been registered) before > assigning, otherwise following warning occurs while making > concatenated device: > > WARNING: CPU: 2 PID: 6728 at drivers/mtd/mtdcore.c:595 > add_mtd_device+0x7f/0x7b0 > > Fixes: 2431c4f5b46c3 ("mtd: Implement mtd_{read,write}() around ...") > Signed-off-by: Zhihao Cheng > --- > drivers/mtd/mtdconcat.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c > index af51eee6b5e8..f685a581df48 100644 > --- a/drivers/mtd/mtdconcat.c > +++ b/drivers/mtd/mtdconcat.c > @@ -694,6 +694,10 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c > concat->mtd._block_markbad = concat_block_markbad; > if (subdev_master->_panic_write) > concat->mtd._panic_write = concat_panic_write; > + if (subdev_master->_read) > + concat->mtd._read = concat_read; > + if (subdev_master->_write) > + concat->mtd._write = concat_write; > > concat->mtd.ecc_stats.badblocks = subdev[0]->ecc_stats.badblocks; > > @@ -755,8 +759,6 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c > concat->mtd.name = name; > > concat->mtd._erase = concat_erase; > - concat->mtd._read = concat_read; > - concat->mtd._write = concat_write; > concat->mtd._sync = concat_sync; > concat->mtd._lock = concat_lock; > concat->mtd._unlock = concat_unlock;