linux-stable/drivers/scsi/ufs
Srinivas Kandagatla b6ca770ae7 scsi: ufs: ufshcd-pltfrm: Fix memory leak due to probe defer
UFS drivers that probe defer will end up leaking memory allocated for clk
and regulator names via kstrdup() because the structure that is holding
this memory is allocated via devm_* variants which will be freed during
probe defer but the names are never freed.

Use same devm_* variant of kstrdup to free the memory allocated to name
when driver probe defers.

Kmemleak found around 11 leaks on Qualcomm Dragon Board RB5:

unreferenced object 0xffff66f243fb2c00 (size 128):
  comm "kworker/u16:0", pid 7, jiffies 4294893319 (age 94.848s)
  hex dump (first 32 bytes):
    63 6f 72 65 5f 63 6c 6b 00 76 69 72 74 75 61 6c  core_clk.virtual
    2f 77 6f 72 6b 71 75 65 75 65 2f 73 63 73 69 5f  /workqueue/scsi_
  backtrace:
    [<000000006f788cd1>] slab_post_alloc_hook+0x88/0x410
    [<00000000cfd1372b>] __kmalloc_track_caller+0x138/0x230
    [<00000000a92ab17b>] kstrdup+0xb0/0x110
    [<0000000037263ab6>] ufshcd_pltfrm_init+0x1a8/0x500
    [<00000000a20a5caa>] ufs_qcom_probe+0x20/0x58
    [<00000000a5e43067>] platform_probe+0x6c/0x118
    [<00000000ef686e3f>] really_probe+0xc4/0x330
    [<000000005b18792c>] __driver_probe_device+0x88/0x118
    [<00000000a5d295e8>] driver_probe_device+0x44/0x158
    [<000000007e83f58d>] __device_attach_driver+0xb4/0x128
    [<000000004bfa4470>] bus_for_each_drv+0x68/0xd0
    [<00000000b89a83bc>] __device_attach+0xec/0x170
    [<00000000ada2beea>] device_initial_probe+0x14/0x20
    [<0000000079921612>] bus_probe_device+0x9c/0xa8
    [<00000000d268bf7c>] deferred_probe_work_func+0x90/0xd0
    [<000000009ef64bfa>] process_one_work+0x29c/0x788
unreferenced object 0xffff66f243fb2c80 (size 128):
  comm "kworker/u16:0", pid 7, jiffies 4294893319 (age 94.848s)
  hex dump (first 32 bytes):
    62 75 73 5f 61 67 67 72 5f 63 6c 6b 00 00 00 00  bus_aggr_clk....
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................

With this patch no memory leaks are reported.

Link: https://lore.kernel.org/r/20210914092214.6468-1-srinivas.kandagatla@linaro.org
Fixes: aa49761309 ("ufs: Add regulator enable support")
Fixes: c6e79dacd8 ("ufs: Add clock initialization support")
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2021-10-20 23:13:37 -04:00
..
cdns-pltfrm.c scsi: ufs: Reduce power management code duplication 2021-08-02 21:43:57 -04:00
Kconfig scsi: ufs: core: SCSI_UFS_HWMON depends on HWMON=y 2021-09-28 23:24:10 -04:00
Makefile scsi: ufs: core: Probe for temperature notification support 2021-09-22 00:07:42 -04:00
tc-dwc-g210-pci.c scsi: ufs: Reduce power management code duplication 2021-08-02 21:43:57 -04:00
tc-dwc-g210-pltfrm.c scsi: ufs: Reduce power management code duplication 2021-08-02 21:43:57 -04:00
tc-dwc-g210.c
tc-dwc-g210.h
ti-j721e-ufs.c
ufs-debugfs.c scsi: ufs: core: Enable power management for wlun 2021-05-10 22:28:20 -04:00
ufs-debugfs.h scsi: ufs: core: Enable power management for wlun 2021-05-10 22:28:20 -04:00
ufs-exynos.c scsi: ufs: mediatek: Support vops pre suspend to disable auto-hibern8 2021-10-12 13:41:01 -04:00
ufs-exynos.h scsi: ufs: ufs-exynos: Fix static checker warning 2021-08-24 23:10:14 -04:00
ufs-fault-injection.c scsi: ufs: Add fault injection support 2021-08-03 07:27:42 -04:00
ufs-fault-injection.h scsi: ufs: Add fault injection support 2021-08-03 07:27:42 -04:00
ufs-hisi.c scsi: ufs: mediatek: Support vops pre suspend to disable auto-hibern8 2021-10-12 13:41:01 -04:00
ufs-hisi.h
ufs-hwmon.c scsi: ufs: core: Add temperature notification exception handling 2021-09-22 00:07:42 -04:00
ufs-mediatek-trace.h
ufs-mediatek.c scsi: ufs: mediatek: Avoid sched_clock() misuse 2021-10-20 23:09:58 -04:00
ufs-mediatek.h scsi: ufs: ufs-mediatek: Introduce default delay for reference clock 2021-10-18 22:38:35 -04:00
ufs-qcom-ice.c
ufs-qcom.c scsi: ufs: mediatek: Support vops pre suspend to disable auto-hibern8 2021-10-12 13:41:01 -04:00
ufs-qcom.h
ufs-sysfs.c scsi: ufs: core: Add lu_enable sysfs node 2021-08-05 23:21:13 -04:00
ufs-sysfs.h
ufs.h scsi: ufs: core: Probe for temperature notification support 2021-09-22 00:07:42 -04:00
ufs_bsg.c scsi: ufs: core: Enable power management for wlun 2021-05-10 22:28:20 -04:00
ufs_bsg.h
ufs_quirks.h scsi: ufs: core: Add L2P entry swap quirk for Micron UFS 2021-08-05 23:21:08 -04:00
ufshcd-crypto.c SCSI misc on 20210219 2021-02-22 10:24:58 -08:00
ufshcd-crypto.h scsi: ufs: use devm_blk_ksm_init() 2021-02-01 12:01:56 +01:00
ufshcd-dwc.c
ufshcd-dwc.h
ufshcd-pci.c scsi: ufs: ufs-pci: Fix Intel LKF link stability 2021-09-13 22:15:51 -04:00
ufshcd-pltfrm.c scsi: ufs: ufshcd-pltfrm: Fix memory leak due to probe defer 2021-10-20 23:13:37 -04:00
ufshcd-pltfrm.h scsi: ufs: Reduce power management code duplication 2021-08-02 21:43:57 -04:00
ufshcd.c scsi: ufs: Call scsi_done() directly 2021-10-16 21:31:42 -04:00
ufshcd.h scsi: ufs: mediatek: Support vops pre suspend to disable auto-hibern8 2021-10-12 13:41:01 -04:00
ufshci-dwc.h
ufshci.h scsi: ufs: Revert "Utilize Transfer Request List Completion Notification Register" 2021-08-02 21:43:58 -04:00
ufshpb.c Merge branch '5.15/scsi-fixes' into 5.16/scsi-staging 2021-10-12 11:58:12 -04:00
ufshpb.h scsi: ufs: ufshpb: Verify that 'num_inflight_map_req' is non-negative 2021-08-11 22:25:36 -04:00
unipro.h