FAILED: patch "[PATCH] mfd: sm501: Fix potential memory leaks during remove" failed to apply to 5.10-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 83feedd9d83c0c5199f98c72df0a6196b4aefb4d
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090352-pavestone-customary-a077@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 83feedd9d83c0c5199f98c72df0a6196b4aefb4d Mon Sep 17 00:00:00 2001
From: Abdun Nihaal <[email protected]>
Date: Mon, 20 Jul 2026 17:08:32 +0530
Subject: [PATCH] mfd: sm501: Fix potential memory leaks during remove
The memory allocated for struct sm501_devdata in sm501_pci_probe() and sm501_plat_probe() is not freed by the corresponding remove functions sm501_pci_remove() and sm501_plat_remove(). Fix that by adding a call to kfree().
drivers/mfd/sm501.c +2 -0
@@ -1627,6 +1627,7 @@ static void sm501_pci_remove(struct pci_dev *dev)release_mem_region (sm->io_res->start,0x100 );pci_disable_device (dev); +kfree (sm); }static void sm501_plat_remove (struct platform_device *dev)
@@ -1637,6 +1638,7 @@ static void sm501_plat_remove(struct platform_device *dev)iounmap (sm->regs);release_mem_region (sm->io_res->start,0x100 ); +kfree (sm); }static const struct pci_device_id sm501_pci_tbl[] = {
Sasha Levin
maintainerPATCH 1/3 mfd: sm501: Remove #ifdef guards for PM related functions
From: Paul Cercueil <[email protected]>
[ Upstream commit 3833239b5ba22256389c2fd83ca70b6a9028435b ]
Use the new pm_sleep_ptr() macro to handle the .suspend/.resume callbacks.
This macro allow the suspend and resume functions to be automatically dropped by the compiler when CONFIG_SUSPEND is disabled, without having to use #ifdef guards.
This has the advantage of always compiling these functions in, independently of any Kconfig option. Thanks to that, bugs and other regressions are subsequently easier to catch.
Stable-dep-of: 83feedd9d83c ("mfd: sm501: Fix potential memory leaks during remove")
--- drivers/mfd/sm501.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/mfd/sm501.c +2 -8
@@ -1434,8 +1434,6 @@ static int sm501_plat_probe(struct platform_device *dev) } -#ifdef CONFIG_PM -/* power management support */ static void sm501_set_power (struct sm501_devdata *sm,int on)
@@ -1511,10 +1509,6 @@ static int sm501_plat_resume(struct platform_device *pdev)return 0 ; } -#else -#define sm501_plat_suspend NULL -#define sm501_plat_resume NULL -#endif /* Initialisation data for PCI devices */
@@ -1716,8 +1710,8 @@ static struct platform_driver sm501_plat_driver = { }, .probe = sm501_plat_probe, .remove = sm501_plat_remove, - .suspend = sm501_plat_suspend, - .resume = sm501_plat_resume, + .suspend = pm_sleep_ptr(sm501_plat_suspend), + .resume = pm_sleep_ptr(sm501_plat_resume), };static int __init sm501_base_init (void )
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 platform: Provide a remove callback that returns no value
From: Uwe Kleine-König <[email protected]>
[ Upstream commit 5c5a7680e67ba6fbbb5f4d79fa41485450c1985c ]
struct platform_driver::remove returning an integer made driver authors expect that returning an error code was proper error handling. However the driver core ignores the error and continues to remove the device because there is nothing the core could do anyhow and reentering the remove callback again is only calling for trouble.
So this is an source for errors typically yielding resource leaks in the error path.
As there are too many platform drivers to neatly convert them all to return void in a single go, do it in several steps after this patch:
a) Convert all drivers to implement .remove_new() returning void instead
of .remove() returning int;
b) Change struct platform_driver::remove() to return void and so make
it identical to .remove_new(); c) Change all drivers back to .remove() now with the better prototype;
d) drop struct platform_driver::remove_new().
While this touches all drivers eventually twice, steps a) and c) can be done one driver after another and so reduces coordination efforts immensely and simplifies review.
Backport notes for 5.10:
- Dispatch .remove_new() from the existing platform_drv_remove() wrapper. Keep its int return type, the legacy .remove() return handling, and unconditional PM-domain detach; this tree predates platform_remove().
- Include the SM501 callback conversion from c20fddf7acfb ("mfd: sm501:
Convert to platform remove callback returning void"): change the existing callback to void, drop its return 0, and select .remove_new(). This gives 83feedd9d83c ("mfd: sm501: Fix potential memory leaks during remove") the context it requires to apply cleanly, without adding any functions.
Stable-dep-of: 83feedd9d83c ("mfd: sm501: Fix potential memory leaks during remove")
--- drivers/base/platform.c | 4 +++- drivers/mfd/sm501.c | 6 ++---- include/linux/platform_device.h | 11 +++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-)
drivers/base/platform.c +3 -1
@@ -783,7 +783,9 @@ static int platform_drv_remove(struct device *_dev)struct platform_device *dev =to_platform_device (_dev);int ret =0 ; -if (drv->remove) +if (drv->remove_new) + drv->remove_new (dev); +else if (drv->remove) ret = drv->remove (dev);dev_pm_domain_detach (_dev, true);
drivers/mfd/sm501.c +2 -4
@@ -1669,7 +1669,7 @@ static void sm501_pci_remove(struct pci_dev *dev)pci_disable_device (dev); } -static int sm501_plat_remove (struct platform_device *dev) +static void sm501_plat_remove (struct platform_device *dev) {struct sm501_devdata *sm =platform_get_drvdata (dev);
@@ -1677,8 +1677,6 @@ static int sm501_plat_remove(struct platform_device *dev)iounmap (sm->regs);release_mem_region (sm->io_res->start,0x100 ); - -return 0 ; }static const struct pci_device_id sm501_pci_tbl[] = {
@@ -1709,7 +1707,7 @@ static struct platform_driver sm501_plat_driver = { .of_match_table = of_sm501_match_tbl, }, .probe = sm501_plat_probe, - .remove = sm501_plat_remove, + .remove_new = sm501_plat_remove, .suspend = pm_sleep_ptr(sm501_plat_suspend), .resume = pm_sleep_ptr(sm501_plat_resume), };
include/linux/platform_device.h +11 -0
@@ -203,7 +203,18 @@ extern void platform_device_put(struct platform_device *pdev);struct platform_driver {int (*probe)(struct platform_device *); + +/* +* Traditionally the remove callback returned an int which however is +* ignored by the driver core. This led to wrong expectations by driver +* authors who thought returning an error code was a valid error +* handling strategy. To convert to a callback returning void, new +* drivers should implement .remove_new() until the conversion it done +* that eventually makes .remove() return void. +*/ int (*remove)(struct platform_device *); +void (*remove_new)(struct platform_device *); +void (*shutdown)(struct platform_device *);int (*suspend)(struct platform_device *,pm_message_t state);int (*resume)(struct platform_device *);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 mfd: sm501: Fix potential memory leaks during remove
In reply to Sasha LevinFrom: Abdun Nihaal <[email protected]>
[ Upstream commit 83feedd9d83c0c5199f98c72df0a6196b4aefb4d ]
The memory allocated for struct sm501_devdata in sm501_pci_probe() and sm501_plat_probe() is not freed by the corresponding remove functions sm501_pci_remove() and sm501_plat_remove(). Fix that by adding a call to kfree().
--- drivers/mfd/sm501.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mfd/sm501.c +2 -0
@@ -1667,6 +1667,7 @@ static void sm501_pci_remove(struct pci_dev *dev)release_mem_region (sm->io_res->start,0x100 );pci_disable_device (dev); +kfree (sm); }static void sm501_plat_remove (struct platform_device *dev)
@@ -1677,6 +1678,7 @@ static void sm501_plat_remove(struct platform_device *dev)iounmap (sm->regs);release_mem_region (sm->io_res->start,0x100 ); +kfree (sm); }static const struct pci_device_id sm501_pci_tbl[] = {
Signature · 1 line
2.53.0