From patchwork Mon Dec 28 12:51:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 353577 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_RED, USER_AGENT_GIT 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 922FAC433DB for ; Mon, 28 Dec 2020 14:32:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6302E2242A for ; Mon, 28 Dec 2020 14:32:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390410AbgL1Obn (ORCPT ); Mon, 28 Dec 2020 09:31:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:39246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2504107AbgL1ObB (ORCPT ); Mon, 28 Dec 2020 09:31:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AC15420715; Mon, 28 Dec 2020 14:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165821; bh=w2MbZqHrbnV1/3vTaIVxhKkrqqnlg4ERx7+X5Is3acI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rsvU26eWK13TazqIE2JHkxpH0AWXXJpmyziCwFS3iz4DujYfZduk2IEv7nDxSnLDr Lkso3fmwwpiuQvrdKM5KkbiIqe0ENUd8XIYvbfJEz+BlvvIX4CFbhGwihZ7EKesvLp FbG+y+Y3cwfmUlk6ERKgrNeWihWyjXIWAQOFxaik= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Richard Weinberger , Miquel Raynal Subject: [PATCH 5.10 666/717] mtd: core: Fix refcounting for unpartitioned MTDs Date: Mon, 28 Dec 2020 13:51:04 +0100 Message-Id: <20201228125052.887156137@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Richard Weinberger commit 1ca71415f075353974524e96ed175306d8a937a8 upstream. Apply changes to usecount also to the master partition. Otherwise we have no refcounting at all if an MTD has no partitions. Cc: stable@vger.kernel.org Fixes: 46b5889cc2c5 ("mtd: implement proper partition handling") Signed-off-by: Richard Weinberger Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20201206202220.27290-1-richard@nod.at Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/mtdcore.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -993,6 +993,8 @@ int __get_mtd_device(struct mtd_info *mt } } + master->usecount++; + while (mtd->parent) { mtd->usecount++; mtd = mtd->parent; @@ -1059,6 +1061,8 @@ void __put_mtd_device(struct mtd_info *m mtd = mtd->parent; } + master->usecount--; + if (master->_put_device) master->_put_device(master);