Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp216395ybb; Thu, 19 Mar 2020 20:16:50 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuspxBprAaH87jRHtvcikHjWsNBFIL6KzBdCi+BQ3hYIONLOqeyVvmJHHZ3SkJqh+flYItt X-Received: by 2002:a9d:7cd1:: with SMTP id r17mr1243736otn.183.1584674210067; Thu, 19 Mar 2020 20:16:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584674210; cv=none; d=google.com; s=arc-20160816; b=pjxpNScmO7+uldNRoo8ICbNlVBSpfen8SULrWOffeurgq393H0pnUD+Y48hDSENohM LvPXMg+inZBPoJao2DK2yZ/b7h2ooJz22KzjUWJqxg8RteL5T/HbRMnS5DHqumW8Jcvy j5UivZ8zbvytv5bqim+VD8l4SlV9Dr4OWSghRrhhP4cgT/yOPEoi+TKt4rbQBTDScF18 mKypsbVxJhiILV4wlwG7+7T1YL+2TYenSmEK3ApRPj91wxEbs3pm5raGXP6uzTbl60DV gCBKVzjjql5y3rxOGvOooLhda6sHDalpd4bMDLDRLyyTAmOts2W3Mo7ojVzxWm5XqFDL Uarg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=J4ejVAFQGBT/9m3OuwpCN/f5zi2+vfyZ3YuZjKutv2I=; b=KX7lGO92PO/9k1qRo5mUpkowzpGFwKOLATeRJal28Z64kNPFvd2G1pXbXV0U1dpAjZ YH4UMEQ8wZWoopwvYeFQixcksKf/Ktq+m07FI0ebHpRxn1VwwBpeLWcqWxP96Akj/IKl /b2sU5WB+R4DjYliw0r6CemHW0kIe613RDnsMipZSi3TgTEQKrxpV9wZiY8a+znM9RWJ gOCV6tyZnDuomGsPzOhf8H3pBZCPZWe7/rsMAfgyZmRD9Cfe8weISjszJxKSiTwEaU2x +yqMjA49pME5VamY/PDMxTO+dsKpgrci4Jzx9GFPg5WQBsXSr/wbVwRP/6T1fiVfZ9iw FztQ== 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 z65si2238277otb.197.2020.03.19.20.16.37; Thu, 19 Mar 2020 20:16:50 -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 S1726866AbgCTDPn (ORCPT + 99 others); Thu, 19 Mar 2020 23:15:43 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:48760 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726809AbgCTDPn (ORCPT ); Thu, 19 Mar 2020 23:15:43 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id CC4E57B9517B1FB8A471; Fri, 20 Mar 2020 11:15:22 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Fri, 20 Mar 2020 11:15:13 +0800 From: Xiaoming Ni To: , , CC: , , , , Subject: [PATCH] mtd:Fix issue where write_cached_data() fails but write() still returns success Date: Fri, 20 Mar 2020 11:15:11 +0800 Message-ID: <1584674111-101462-1-git-send-email-nixiaoming@huawei.com> X-Mailer: git-send-email 1.8.5.6 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.189.174] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org mtdblock_flush() -->write_cached_data() --->erase_write() mtdblock: erase of region [0x40000, 0x20000] on "xxx" failed Because mtdblock_flush() always returns 0, even if write_cached_data() fails and data is not written to the device, syscall_write() still returns success Signed-off-by: Xiaoming Ni --- drivers/mtd/mtdblock.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c index c06b532..078e0f6 100644 --- a/drivers/mtd/mtdblock.c +++ b/drivers/mtd/mtdblock.c @@ -294,12 +294,13 @@ static void mtdblock_release(struct mtd_blktrans_dev *mbd) static int mtdblock_flush(struct mtd_blktrans_dev *dev) { struct mtdblk_dev *mtdblk = container_of(dev, struct mtdblk_dev, mbd); + int ret; mutex_lock(&mtdblk->cache_mutex); - write_cached_data(mtdblk); + ret = write_cached_data(mtdblk); mutex_unlock(&mtdblk->cache_mutex); mtd_sync(dev->mtd); - return 0; + return ret; } static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) -- 1.8.5.6