From: Zijun Hu <zijun_hu@icloud.com>
To: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
Helge Deller <deller@gmx.de>,
"David S. Miller" <davem@davemloft.net>,
Andreas Larsson <andreas@gaisler.com>,
linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org,
sparclinux@vger.kernel.org, Zijun Hu <zijun.hu@oss.qualcomm.com>
Subject: Re: [PATCH v5 5/8] char: misc: Fix kunit test case miscdev_test_dynamic_reentry() failure
Date: Mon, 14 Jul 2025 09:02:09 +0800 [thread overview]
Message-ID: <8a0bfdc6-5edb-4ca0-b142-067eb94ef57f@icloud.com> (raw)
In-Reply-To: <aHADQWaYsjK5EYsN@quatroqueijos.cascardo.eti.br>
On 2025/7/11 02:15, Thadeu Lima de Souza Cascardo wrote:
> Adding a failing test and then fixing the code does not seem the best way
> to justify this change. I would rather add the fix with a proper
> justification and then add the test.
>
may need to only correct commit message. the order about unit test and
fix may be right as last reply.
> On the other hand, I have found real cases where this might happen, some by
> code inspection only, but I also managed to reproduce the issue here,
> where:
>
> 1) wmi/dell-smbios registered minor 122, acpi_thermal_rel registered minor
> 123.
> 2) unbind "int3400 thermal" driver from its device, this will unregister
> acpi_thermal_rel
> 3) remove dell_smbios module
> 4) reinstall dell_smbios module, now wmi/dell-smbios is using misc 123
> 5) bind the device to "int3400 thermal" driver again, acpi_thermal_rel
> fails to register
>
above issue should not happen with current char-misc tree since fixed
minor have no such reentry issue:
for any fixed minor fixed_A in range [0, 255): ".minor = fixed_A" ->
registered -> ".minor = fixed_A" -> de-registered -> ".minor = fixed_A"
, namely, for fixed minor, it is always un-changed about registering
and de-registering.
> I think we have a few options to fix these bugs:
>
> 1) Apply your suggested fix.
> 2) Fix all the buggy drivers.
> 3) Change API and have the minor be a misc_register parameter.
>
> The advantage of your option is that it is simple and contained and easy to
> backport.
>
> Changing API would require changing a lot of code and hard to backport, but
> I find it less error-prone than requiring the minor member to be reset, if
> we end up deciding about fixing the drivers.
>
> As for fixing individual drivers, one helpful feature is applying your
> previous patch [1], but perhaps with stronger message, maybe a WARN_ON.
>
> [1] char: misc: Disallow registering miscdevice whose minor > MISC_DYNAMIC_MINOR
>
> I am leaning towards your suggested fix, but with different wording, and
> before adding the test case.
>
> Something like:
>
> Some drivers may reuse the miscdevice structure after they are
> deregistered. If the intention is to allocate a dynamic minor, if the minor
> number is not reset to MISC_DYNAMIC_MINOR before calling misc_register, it
> will try to register a previously dynamically allocated minor number, which
> may have been registered by a different driver.
>
let me correct commit message based on this suggestions.
thank you.
> One such case is the acpi_thermal_rel misc device, registered by the
> int3400 thermal driver. If the device is unbound from the driver and later
> bound, if there was another dynamic misc device registered in between, it
> would fail to register the acpi_thermal_rel misc device. Other drivers
> behave similarly.
>
> Instead of fixing all the drivers, just reset the minor member to
> MISC_DYNAMIC_MINOR when calling misc_deregister in case it was a
> dynamically allocated minor number.
next prev parent reply other threads:[~2025-07-14 1:02 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-10 11:56 [PATCH v5 0/8] char: misc: Various cleanup for miscdevice Zijun Hu
2025-07-10 11:56 ` [PATCH v5 1/8] char: misc: Move drivers/misc/misc_minor_kunit.c to drivers/char/ Zijun Hu
2025-07-10 11:56 ` [PATCH v5 2/8] char: misc: Adapt and add test cases for simple minor space division Zijun Hu
2025-07-10 14:34 ` Thadeu Lima de Souza Cascardo
2025-07-14 0:42 ` Zijun Hu
2025-07-10 11:56 ` [PATCH v5 3/8] char: misc: Disallow registering miscdevice whose minor > MISC_DYNAMIC_MINOR Zijun Hu
2025-07-10 11:56 ` [PATCH v5 4/8] char: misc: Add a case to test registering miscdevice again without reinitialization Zijun Hu
2025-07-10 11:56 ` [PATCH v5 5/8] char: misc: Fix kunit test case miscdev_test_dynamic_reentry() failure Zijun Hu
2025-07-10 18:15 ` Thadeu Lima de Souza Cascardo
2025-07-14 1:02 ` Zijun Hu [this message]
2025-07-14 11:26 ` Thadeu Lima de Souza Cascardo
2025-07-10 11:56 ` [PATCH v5 6/8] char: misc: Does not request module for miscdevice with dynamic minor Zijun Hu
2025-07-10 18:22 ` Thadeu Lima de Souza Cascardo
2025-07-10 11:56 ` [PATCH v5 7/8] char: misc: Register fixed minor EISA_EEPROM_MINOR in linux/miscdevice.h Zijun Hu
2025-07-10 11:56 ` [PATCH v5 8/8] sparc: kernel: apc: Remove macro APC_MINOR definition Zijun Hu
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=8a0bfdc6-5edb-4ca0-b142-067eb94ef57f@icloud.com \
--to=zijun_hu@icloud.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=andreas@gaisler.com \
--cc=arnd@arndb.de \
--cc=cascardo@igalia.com \
--cc=davem@davemloft.net \
--cc=deller@gmx.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=sparclinux@vger.kernel.org \
--cc=zijun.hu@oss.qualcomm.com \
/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 NNTP newsgroup(s).