Received: by 2002:ab2:7988:0:b0:1f4:b336:87c4 with SMTP id g8csp84116lqj; Thu, 11 Apr 2024 10:25:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV5RV8fEnn5Gu5oHdTD/k93Fbuk+r3c3yHiZqrajnICEn+Ubxm9V+d2Er8XQzvXb/xVhLcRgsYyznLbLxnpL3hBLpjjwAtcJDVW5DlnEg== X-Google-Smtp-Source: AGHT+IHwqIIWmAspBf6gJ0MuQKp6P9G67jHlsnq9qeFuRj/FD1iO579UyHFf6zJOvhOjXrfjx0He X-Received: by 2002:a17:90a:ee89:b0:2a5:d5b1:b99b with SMTP id i9-20020a17090aee8900b002a5d5b1b99bmr202955pjz.38.1712856330613; Thu, 11 Apr 2024 10:25:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712856330; cv=pass; d=google.com; s=arc-20160816; b=a6IWpZ4BGAG7z9skPrIhcBSAaKMRzbhNfuD50zEBrAP8xpQo4oo6+Gq/h8nwQM8rCF FYrkblrIghIM1C7nOEnLjwoM74gklu9d8Tr6+SIdMSB52hDZttmisLt82G4IonvvbLy4 TZOiSEuFf+cwBLiovsqhQ4CJSNJHri1AiRxnf+aJ+RHCvX/huaTiqeF5s/Gn08dNVOqR 4QQr5niVovM0k0GNRKMQwwp5IHvCwZ4feV0/9P11Gh0cx1C4E94NFiHZBTtHsb/FmOAI qV+2m6E3WMMYcrpPYa0wIy+UQsta7DfjakPkyiCb1JZe6T0XXxHoZYEZFGSv20hpIbEq WAsQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=lY3EilLid0yoX1QKyUbPrpVbtoTNlt+X6aSs0bPCw/U=; fh=Si6bMNarEfnsfGk7CiDb8JjBwfFHQ6SftQ7iAE1hSzA=; b=JysLIJ6wvOZfM3KAN7SL93NQuM/8A4nuKG19pawo8VJwmBXH4pOX/28L/2w6uR8b6f gANM00cstutupHJqD3abHIeZ5Em062NSBmX9c/NuM16Mf/bMVRRMp6PAhF3GIBbtk81O L2TJ75JJ7JGEZxCFAoUZw6SnR8VqLWtV/OpA88oaleAkzRw9J3khg5vCIDVBZ9GqqHb1 uyGdrKK50pb5J6J4eOiGRheCgYNMugyvqYdnDUOX1gQij2NwNd8LQzuxLXC0pEwx6XY+ gQ04xyZzRCM0q6axHNO4PSE1RmTBgIGFi3oulDcuRED95S1siiW1nsQoAG2cDGImPS5z ZclA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-141228-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141228-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a9-20020a17090a8c0900b0029bb297c136si1682826pjo.67.2024.04.11.10.25.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 10:25:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141228-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-141228-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141228-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2AB4E280C65 for ; Thu, 11 Apr 2024 17:22:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1727718633; Thu, 11 Apr 2024 15:48:31 +0000 (UTC) Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C92A182BD for ; Thu, 11 Apr 2024 15:48:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712850510; cv=none; b=gfvS6eT+fhzfnEL7bE/OwewhykpMYRUoN+2Duj1DN3bFGGPyYIbo97GAawd/kB2kad+4qYX9NV7TscFzr5iCinHbyEN4m+l58WSzRpEumuMrWUApPLpO8l+NPYr4lBzJz76ql+WGTdHsBogSaURXaljroyngeQ4wzaKeVso5WhQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712850510; c=relaxed/simple; bh=gxmEWGIJE5OWqT4IoVnr60s9cNY+kcDdy9T3WnwihIs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rPYTbYiU+tXEC7nFswT2ECVK/NZYsygYJ0fd9BXDWr7mDPQ9pAltmmhLb1O96D7lROWpxQZgNKLtcsANu8cphTP6LUX9yMiwBG3Vbv2xtLwoVU9WEZJnWkHe+qEq4R6d3VMvIRoo/9zZGcUj7UalpUb8DcFjBlxcFV2mTVLFOPw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96.2) (envelope-from ) id 1ruwes-0006Iz-2b; Thu, 11 Apr 2024 15:48:14 +0000 Date: Thu, 11 Apr 2024 16:48:12 +0100 From: Daniel Golle To: Zhihao Cheng Cc: richard@nod.at, miquel.raynal@bootlin.com, ben.hutchings@mind.be, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/4] ubi: ubi_init: Fix missed ubiblock cleanup in error handling path Message-ID: References: <20240411031903.3050278-1-chengzhihao1@huawei.com> <20240411031903.3050278-3-chengzhihao1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240411031903.3050278-3-chengzhihao1@huawei.com> On Thu, Apr 11, 2024 at 11:19:01AM +0800, Zhihao Cheng wrote: > The ubiblock_init called by ubi_init will register device number, but > device number is not released in error handling path of ubi_init when > ubi is loaded by inserting module (eg. attaching failure), which leads > to subsequent ubi_init calls failed by running out of device number > (dmesg shows that "__register_blkdev: failed to get major for ubiblock"). > Since ubiblock_init() registers notifier and invokes notification > functions, so we can move it after ubi_init_attach() to fix the problem. > > Fixes: 927c145208b0 ("mtd: ubi: attach from device tree") > Signed-off-by: Zhihao Cheng > --- > drivers/mtd/ubi/build.c | 51 +++++++++++++++++++++-------------------- > 1 file changed, 26 insertions(+), 25 deletions(-) > > diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c > index 7f95fd7968a8..bc63fbf5e947 100644 > --- a/drivers/mtd/ubi/build.c > +++ b/drivers/mtd/ubi/build.c > @@ -1263,9 +1263,21 @@ static struct mtd_notifier ubi_mtd_notifier = { > .remove = ubi_notify_remove, > }; > > +static void detach_mtd_devs(int count) Missing __init to avoid section missmatch. See also: https://lore.kernel.org/oe-kbuild-all/202404112327.158HJfAw-lkp@intel.com/ > +{ > + int i; > + > + for (i = 0; i < count; i++) > + if (ubi_devices[i]) { > + mutex_lock(&ubi_devices_mutex); > + ubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1); > + mutex_unlock(&ubi_devices_mutex); > + } > +} > + > static int __init ubi_init_attach(void) > { > - int err, i, k; > + int err, i; > > /* Attach MTD devices */ > for (i = 0; i < mtd_devs; i++) { > @@ -1317,12 +1329,7 @@ static int __init ubi_init_attach(void) > return 0; > > out_detach: > - for (k = 0; k < i; k++) > - if (ubi_devices[k]) { > - mutex_lock(&ubi_devices_mutex); > - ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1); > - mutex_unlock(&ubi_devices_mutex); > - } > + detach_mtd_devs(i); > return err; > } > #ifndef CONFIG_MTD_UBI_MODULE > @@ -1366,15 +1373,6 @@ static int __init ubi_init(void) > if (err) > goto out_slab; > > - err = ubiblock_init(); > - if (err) { > - pr_err("UBI error: block: cannot initialize, error %d\n", err); > - > - /* See comment above re-ubi_is_module(). */ > - if (ubi_is_module()) > - goto out_debugfs; > - } > - > register_mtd_user(&ubi_mtd_notifier); > > if (ubi_is_module()) { > @@ -1383,11 +1381,21 @@ static int __init ubi_init(void) > goto out_mtd_notifier; > } > > + err = ubiblock_init(); > + if (err) { > + pr_err("UBI error: block: cannot initialize, error %d\n", err); > + > + /* See comment above re-ubi_is_module(). */ > + if (ubi_is_module()) > + goto out_detach; > + } > + > return 0; > > +out_detach: > + detach_mtd_devs(mtd_devs); > out_mtd_notifier: > unregister_mtd_user(&ubi_mtd_notifier); > -out_debugfs: > ubi_debugfs_exit(); > out_slab: > kmem_cache_destroy(ubi_wl_entry_slab); > @@ -1403,17 +1411,10 @@ device_initcall(ubi_init); > > static void __exit ubi_exit(void) > { > - int i; > - > ubiblock_exit(); > unregister_mtd_user(&ubi_mtd_notifier); > > - for (i = 0; i < UBI_MAX_DEVICES; i++) > - if (ubi_devices[i]) { > - mutex_lock(&ubi_devices_mutex); > - ubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1); > - mutex_unlock(&ubi_devices_mutex); > - } > + detach_mtd_devs(UBI_MAX_DEVICES); > ubi_debugfs_exit(); > kmem_cache_destroy(ubi_wl_entry_slab); > misc_deregister(&ubi_ctrl_cdev); > -- > 2.39.2 >