Linux-mtd Archive mirror
 help / color / mirror / Atom feed
From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Daniel Golle <daniel@makrotopia.org>
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
Date: Fri, 12 Apr 2024 09:20:28 +0800	[thread overview]
Message-ID: <fb1de5ee-46d3-7148-7b59-a5d736e00f1c@huawei.com> (raw)
In-Reply-To: <ZhgGPE_5urw2izAA@makrotopia.org>

在 2024/4/11 23:48, Daniel Golle 写道:
> 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 <chengzhihao1@huawei.com>
>> ---
>>   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/

I think function without '__init' attributes can be called in ubi_init, 
for example misc_register, kmem_cache_create, and I verify it by make 
W=1 in local machine. And above warning(in your link) is only detected 
in my v1 series.
After investigating the '__init' and '__exit', I understand that there 
are two independent text section for these functions, for example, 
__init text section will be removed from memory after it is finished, so 
we cannot call __exit function in __init function.
> 
>> +{
>> +	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);
>> +		}
>> +}



______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2024-04-12  1:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11  3:18 [PATCH v2 0/4] ubi: Fix serious of resource leaking problems Zhihao Cheng
2024-04-11  3:19 ` [PATCH v2 1/4] ubi: ubi_init: Fix missed debugfs cleanup in error handling path Zhihao Cheng
2024-04-11  3:19 ` [PATCH v2 2/4] ubi: ubi_init: Fix missed ubiblock " Zhihao Cheng
2024-04-11 15:48   ` Daniel Golle
2024-04-12  1:20     ` Zhihao Cheng [this message]
2024-04-11 16:43   ` Markus Elfring
2024-04-11  3:19 ` [PATCH v2 3/4] mtd: ubi: Ignore all debugfs initialisation failures Zhihao Cheng
2024-04-11  3:19 ` [PATCH v2 4/4] ubi: debugfs: Replace IS_ERR_OR_NULL with IS_ERR in error checking path Zhihao Cheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fb1de5ee-46d3-7148-7b59-a5d736e00f1c@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=ben.hutchings@mind.be \
    --cc=daniel@makrotopia.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).