mfd: ls2kbmc: A fix and a refactoring
v2 cover mfd: ls2kbmc: A fix and a refactoring
Just an ad-hoc fix and refactoring as I have noticed the problematic fix, which is commit 4af66c2bcab0 ("mfd: ls2kbmc: check for devm_mfd_add_devices() failure") in the Linux Next.
The best, actually to get that change simply being dropped or reverted, as this whole series was induced by that (wrong) attempt to fix things.
Changelog v2:
- fixed spelling (Lee)
- rebased on top of for-mfd-next (Lee)
- collected tags (Binbin)
v1: <[email protected]>
Andy Shevchenko (2):
mfd: ls2kbmc: Fully convert to use managed resources
mfd: ls2kbmc: Use PCI API instead of direct accesses
drivers/mfd/ls2k-bmc-core.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-)
Signature · 1 line
2.50.1
PATCH v2 1/2 mfd: ls2kbmc: Fully convert to use managed resources
The mixing of managed and non-managed resources may lead to possible use-after-free bugs. In this driver the problematic part is the device functionality that may just have gone behind the functions back, e.g., when interrupt is being served. Fix this by switching to managed resources for PCI.
--- drivers/mfd/ls2k-bmc-core.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-)
drivers/mfd/ls2k-bmc-core.c +7 -21
@@ -464,25 +464,23 @@ static int ls2k_bmc_probe(struct pci_dev *dev, const struct pci_device_id *id)resource_size_t base;int ret; - ret =pci_enable_device (dev); + ret =pcim_enable_device (dev);if (ret)return ret; ddata =devm_kzalloc (&dev->dev,sizeof (*ddata),GFP_KERNEL ); -if (!ddata) { - ret = -ENOMEM ; - goto disable_pci; - } +if (!ddata) +return -ENOMEM ; ddata->dev = &dev->dev; ret =ls2k_bmc_init (ddata);if (ret) - goto disable_pci; +return ret; ret =ls2k_bmc_parse_mode (dev, &pd);if (ret) - goto disable_pci; +return ret; ls2k_bmc_cells[LS2K_BMC_DISPLAY ].platform_data = &pd; ls2k_bmc_cells[LS2K_BMC_DISPLAY ].pdata_size =sizeof (pd);
@@ -490,23 +488,12 @@ static int ls2k_bmc_probe(struct pci_dev *dev, const struct pci_device_id *id)/* Remove conflicting efifb device */ ret =aperture_remove_conflicting_devices (base,SZ_4M ,"simple-framebuffer" ); -if (ret) { -dev_err (&dev->dev,"Failed to removed firmware framebuffers: %d\n" , ret); - goto disable_pci; - } +if (ret) +return dev_err_probe (&dev->dev, ret,"Failed to remove firmware framebuffers\n" );return devm_mfd_add_devices (&dev->dev,PLATFORM_DEVID_AUTO , ls2k_bmc_cells,ARRAY_SIZE (ls2k_bmc_cells), &dev->resource[0 ],0 ,NULL ); - -disable_pci: -pci_disable_device (dev); -return ret; -} - -static void ls2k_bmc_remove (struct pci_dev *dev) -{ -pci_disable_device (dev); }static struct pci_device_id ls2k_bmc_devices[] = {
@@ -519,7 +506,6 @@ static struct pci_driver ls2k_bmc_driver = { .name = "ls2k-bmc", .id_table = ls2k_bmc_devices, .probe = ls2k_bmc_probe, - .remove = ls2k_bmc_remove, };module_pci_driver (ls2k_bmc_driver);
Signature · 1 line
2.50.1
Lee Jones
maintainerRe: [PATCH v2 1/2] mfd: ls2kbmc: Fully convert to use managed resources
Quoted 6 lines · Andy Shevchenko
The mixing of managed and non-managed resources may lead to possible use-after-free bugs. In this driver the problematic part is the device functionality that may just have gone behind the functions back, e.g., when interrupt is being served. Fix this by switching to managed resources for PCI.
Quoted 7 lines
Fixes 91a3e1f5453a ("mfd: ls2kbmc: Check for devm_mfd_add_devices() failure")Fixes d952bba3fbb5 ("mfd: ls2kbmc: Add Loongson-2K BMC reset function support")Reviewed-by Binbin Zhou <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/mfd/ls2k-bmc-core.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-)
Still doesn't apply. I'm getting lots of conflicts.
What base are you on?
% git --no-pager log --oneline drivers/mfd/ls2k-bmc-core.c3696ac1d0db2 mfd: ls2kbmc: Remove unneeded semicolon from ls2k_bmc_recover_pci_data() d952bba3fbb5 mfd: ls2kbmc: Add Loongson-2K BMC reset function support 0d64f6d1ffe9 mfd: ls2kbmc: Introduce Loongson-2K BMC core driver
Signature · 1 line
Lee Jones [李琼斯]
Re: [PATCH v2 1/2] mfd: ls2kbmc: Fully convert to use managed resources
Quoted 16 lines · Lee Jones
Quoted 6 lines · Andy Shevchenko
The mixing of managed and non-managed resources may lead to possible use-after-free bugs. In this driver the problematic part is the device functionality that may just have gone behind the functions back, e.g., when interrupt is being served. Fix this by switching to managed resources for PCI.
Quoted 7 lines
Fixes 91a3e1f5453a ("mfd: ls2kbmc: Check for devm_mfd_add_devices() failure")Fixes d952bba3fbb5 ("mfd: ls2kbmc: Add Loongson-2K BMC reset function support")Reviewed-by Binbin Zhou <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/mfd/ls2k-bmc-core.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-)
Quoted 3 lines
Still doesn't apply. I'm getting lots of conflicts.
What base are you on?
Linux Next which includes your -fixes branch. You probably need to merge either it or v6.18-rc6 to the -next. Then the v1 will be okay to apply.
The bottom line is that without doing that we will have conflicts either in Linux Next followed by merging by Linus or in your branches locally before going to the above mentioned.
Another possibility is cherry-pick patches from -fixes to -next.
And alternative is to wait for -rc1 and rebase this on top of and apply then.
Quoted 4 lines
% git --no-pager log --oneline
drivers/mfd/ls2k-bmc-core.c3696ac1d0db2mfd: ls2kbmc: Remove unneeded semicolon fromls2k_bmc_recover_pci_data()d952bba3fbb5mfd: ls2kbmc: Add Loongson-2K BMC reset function support0d64f6d1ffe9mfd: ls2kbmc: Introduce Loongson-2K BMC core driver
Signature · 2 lines
With Best Regards, Andy Shevchenko
Lee Jones
maintainerRe: [PATCH v2 1/2] mfd: ls2kbmc: Fully convert to use managed resources
Quoted 17 lines · Andy Shevchenko
Quoted 16 lines · Lee Jones
Quoted 13 lines · Andy Shevchenko
The mixing of managed and non-managed resources may lead to possible use-after-free bugs. In this driver the problematic part is the device functionality that may just have gone behind the functions back, e.g., when interrupt is being served. Fix this by switching to managed resources for PCI.
Fixes 91a3e1f5453a ("mfd: ls2kbmc: Check for devm_mfd_add_devices() failure")Fixes d952bba3fbb5 ("mfd: ls2kbmc: Add Loongson-2K BMC reset function support")Reviewed-by Binbin Zhou <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/mfd/ls2k-bmc-core.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-)
Quoted 6 lines
Quoted 3 lines
Still doesn't apply. I'm getting lots of conflicts.
What base are you on?
Linux Next which includes your -fixes branch. You probably need to merge either it or v6.18-rc6 to the -next. Then the v1 will be okay to apply.
Ah, yes, that explains it.
Quoted 8 lines
The bottom line is that without doing that we will have conflicts either in Linux Next followed by merging by Linus or in your branches locally before going to the above mentioned.
Another possibility is cherry-pick patches from -fixes to -next.
And alternative is to wait for -rc1 and rebase this on top of and apply then.
Yes, if there is no urgency, we can wait for the next merge window.
Signature · 1 line
Lee Jones [李琼斯]
Re: [PATCH v2 1/2] mfd: ls2kbmc: Fully convert to use managed resources
Quoted 3 lines · Lee Jones
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Lee Jones
On Thu, 13 Nov 2025, Andy Shevchenko wrote:
...
Quoted 21 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Fixes 91a3e1f5453a ("mfd: ls2kbmc: Check for devm_mfd_add_devices() failure")Fixes d952bba3fbb5 ("mfd: ls2kbmc: Add Loongson-2K BMC reset function support")Reviewed-by Binbin Zhou <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/mfd/ls2k-bmc-core.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-)Quoted 6 lines
Quoted 3 lines
Still doesn't apply. I'm getting lots of conflicts.
What base are you on?
Linux Next which includes your -fixes branch. You probably need to merge either it or v6.18-rc6 to the -next. Then the v1 will be okay to apply.
Ah, yes, that explains it.
Quoted 4 lines
The bottom line is that without doing that we will have conflicts either in Linux Next followed by merging by Linus or in your branches locally before going to the above mentioned.
Quoted 6 lines
Quoted 4 lines
Another possibility is cherry-pick patches from -fixes to -next.
And alternative is to wait for -rc1 and rebase this on top of and apply then.
Yes, if there is no urgency,
It's up to you and the author of the code, it's a fix, but I don't think it's too critical, we can wait, yes.
Quoted 1 line
we can wait for the next merge window.
It's a fix, do you mean to apply after -rc1 for v6.19-rcX?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Lee Jones
maintainerRe: [PATCH v2 1/2] mfd: ls2kbmc: Fully convert to use managed resources
Quoted 33 lines · Andy Shevchenko
Quoted 3 lines · Lee Jones
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Lee Jones
On Thu, 13 Nov 2025, Andy Shevchenko wrote:
...
Quoted 25 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Fixes 91a3e1f5453a ("mfd: ls2kbmc: Check for devm_mfd_add_devices() failure")Fixes d952bba3fbb5 ("mfd: ls2kbmc: Add Loongson-2K BMC reset function support")Reviewed-by Binbin Zhou <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/mfd/ls2k-bmc-core.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-)Quoted 6 lines
Quoted 3 lines
Still doesn't apply. I'm getting lots of conflicts.
What base are you on?
Linux Next which includes your -fixes branch. You probably need to merge either it or v6.18-rc6 to the -next. Then the v1 will be okay to apply.
Ah, yes, that explains it.
Quoted 8 lines
The bottom line is that without doing that we will have conflicts either in Linux Next followed by merging by Linus or in your branches locally before going to the above mentioned.
Another possibility is cherry-pick patches from -fixes to -next.
And alternative is to wait for -rc1 and rebase this on top of and apply then.
Quoted 8 lines
Quoted 1 line
Yes, if there is no urgency,
It's up to you and the author of the code, it's a fix, but I don't think it's too critical, we can wait, yes.
Quoted 1 line
we can wait for the next merge window.
It's a fix, do you mean to apply after -rc1 for v6.19-rcX?
Yes, we can merged it though for-mfd-fixes.
Signature · 1 line
Lee Jones [李琼斯]
Re: [PATCH v2 1/2] mfd: ls2kbmc: Fully convert to use managed resources
Quoted 5 lines · Lee Jones
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Lee Jones
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Lee Jones
On Thu, 13 Nov 2025, Andy Shevchenko wrote:
...
Quoted 28 lines
Quoted 28 lines
Quoted 27 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Fixes 91a3e1f5453a ("mfd: ls2kbmc: Check for devm_mfd_add_devices() failure")Fixes d952bba3fbb5 ("mfd: ls2kbmc: Add Loongson-2K BMC reset function support")Reviewed-by Binbin Zhou <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/mfd/ls2k-bmc-core.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-)Quoted 6 lines
Quoted 3 lines
Still doesn't apply. I'm getting lots of conflicts.
What base are you on?
Linux Next which includes your -fixes branch. You probably need to merge either it or v6.18-rc6 to the -next. Then the v1 will be okay to apply.
Ah, yes, that explains it.
Quoted 8 lines
The bottom line is that without doing that we will have conflicts either in Linux Next followed by merging by Linus or in your branches locally before going to the above mentioned.
Another possibility is cherry-pick patches from -fixes to -next.
And alternative is to wait for -rc1 and rebase this on top of and apply then.
Yes, if there is no urgency,
Quoted 8 lines
Quoted 6 lines
It's up to you and the author of the code, it's a fix, but I don't think it's too critical, we can wait, yes.
Quoted 1 line
we can wait for the next merge window.
It's a fix, do you mean to apply after -rc1 for v6.19-rcX?
Yes, we can merged it though for-mfd-fixes.
Okay, let's wait for v6.19-rc1 then.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: (subset) [PATCH v2 1/2] mfd: ls2kbmc: Fully convert to use managed resources
In reply to Andy ShevchenkoQuoted 8 lines · Andy Shevchenko
The mixing of managed and non-managed resources may lead to possible use-after-free bugs. In this driver the problematic part is the device functionality that may just have gone behind the functions back, e.g., when interrupt is being served. Fix this by switching to managed resources for PCI.
[...]
Applied, thanks!
[1/2] mfd: ls2kbmc: Fully convert to use managed resources
commit: 5bf5a793afc97fad001864d4268a45d355703956
--
Lee Jones [李琼斯]
PATCH v2 2/2 mfd: ls2kbmc: Use PCI API instead of direct accesses
In reply to Andy ShevchenkoThere is a PCI API to access device resources. Use it instead of direct accesses.
--- drivers/mfd/ls2k-bmc-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mfd/ls2k-bmc-core.c +2 -2
@@ -484,7 +484,7 @@ static int ls2k_bmc_probe(struct pci_dev *dev, const struct pci_device_id *id) ls2k_bmc_cells[LS2K_BMC_DISPLAY ].platform_data = &pd; ls2k_bmc_cells[LS2K_BMC_DISPLAY ].pdata_size =sizeof (pd); - base = dev->resource[0 ].start +LS2K_DISPLAY_RES_START ; + base =pci_resource_start (dev,0 ) +LS2K_DISPLAY_RES_START ;/* Remove conflicting efifb device */ ret =aperture_remove_conflicting_devices (base,SZ_4M ,"simple-framebuffer" );
@@ -493,7 +493,7 @@ static int ls2k_bmc_probe(struct pci_dev *dev, const struct pci_device_id *id)return devm_mfd_add_devices (&dev->dev,PLATFORM_DEVID_AUTO , ls2k_bmc_cells,ARRAY_SIZE (ls2k_bmc_cells), - &dev->resource[0 ],0 ,NULL ); +pci_resource_n (dev,0 ),0 ,NULL ); }static struct pci_device_id ls2k_bmc_devices[] = {
Signature · 1 line
2.50.1
Quoted 8 lines · Andy Shevchenko
Just an ad-hoc fix and refactoring as I have noticed the problematic fix, which is commit
4af66c2bcab0("mfd: ls2kbmc: check fordevm_mfd_add_devices()failure") in the Linux Next.The best, actually to get that change simply being dropped or reverted, as this whole series was induced by that (wrong) attempt to fix things.
[...]
Applied, thanks!
[1/2] mfd: ls2kbmc: Fully convert to use managed resources
commit: 5bf5a793afc97fad001864d4268a45d355703956
[2/2] mfd: ls2kbmc: Use PCI API instead of direct accesses
commit: 13f3c189c8d298930cfb92efaf037f9af0db5569--
Lee Jones [李琼斯]