SD card bug fixes
cover SD card bug fixes
These patches include SD card genernal bug fixes.
Bao D. Nguyen (2):
mmc: core: Add a cap to use long discard size
mmc: sd: Fix trivial SD card issues
Can Guo (2):
mmc: core: fix SD card request queue refcount underflow during
shutdown
mmc: core: fix one NULL pointer dereference after SD card is removed
Sahitya Tummala (1):
mmc: sdhci-msm: Ignore data timeout error for R1B commands
Subhash Jadavani (1):
mmc: core: remove shutdown handler
Sujith Reddy Thumma (1):
mmc: core: Skip frequency retries for SDCC slots
Vijay Viswanath (1):
mmc: host: Add device_prepare pm for mmc_host
Ziqi Chen (1):
mmc: core: allow hosts to specify a large discard size
drivers/mmc/core/block.c | 4 ++-- drivers/mmc/core/bus.c | 13 +++++++++++++ drivers/mmc/core/core.c | 26 +++++++++++++------------- drivers/mmc/core/host.c | 19 +++++++++++++++++++ drivers/mmc/core/mmc.c | 22 ---------------------- drivers/mmc/core/queue.c | 10 +++++++--- drivers/mmc/core/sd.c | 10 ++++++---- drivers/mmc/host/sdhci.c | 15 +++++++++------ drivers/mmc/host/sdhci.h | 7 +++++++ include/linux/mmc/host.h | 1 + 10 files changed, 77 insertions(+), 50 deletions(-)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 1/9 mmc: core: Add a cap to use long discard size
Add MMC_CAP2_MAX_DISCARD_SIZE cap which allows setting the max discard size value if needed.
Setting a high value for the max discard size is to fix an issue where some SD cards take a long time to perform the card format.
--- include/linux/mmc/host.h | 1 + 1 file changed, 1 insertion(+)
include/linux/mmc/host.h +1 -0
@@ -348,6 +348,7 @@ struct mmc_host {#define MMC_CAP2_FULL_PWR_CYCLE (1 << 2)/* Can do full power cycle */ #define MMC_CAP2_HS200_1_8V_SDR (1 << 5)/* can support */ #define MMC_CAP2_HS200_1_2V_SDR (1 << 6)/* can support */ +#define MMC_CAP2_MAX_DISCARD_SIZE (1 << 8)/* use max discard, ignoring max_busy_timeout parameter */ #define MMC_CAP2_HS200 (MMC_CAP2_HS200_1_8V_SDR | \ MMC_CAP2_HS200_1_2V_SDR)#define MMC_CAP2_CD_ACTIVE_HIGH (1 << 10)/* Card-detect signal active high */
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [<PATCH v1> 1/9] mmc: core: Add a cap to use long discard size
Quoted 5 lines · Bao D. Nguyen
Add
MMC_CAP2_MAX_DISCARD_SIZEcap which allows setting the max discard size value if needed.
Setting a high value for the max discard size is to fix an issue where some SD cards take a long time to perform the card format.
Can you please explain elaborate on why the SD card takes a long time to "format"? What goes on and what takes time, etc.
In any case, it looks wrong to add a host cap to solve this problem.
Kind regards
Uffe
Quoted 21 lines
Signed-off-by Bao D. Nguyen <[email protected]>--- include/linux/mmc/host.h | 1 + 1 file changed, 1 insertion(+)include/linux/mmc/host.h +1
-1@@ -348,6 +348,7 @@ struct mmc_host {#define MMC_CAP2_FULL_PWR_CYCLE (1 << 2)/* Can do full power cycle */ #define MMC_CAP2_HS200_1_8V_SDR (1 << 5)/* can support */ #define MMC_CAP2_HS200_1_2V_SDR (1 << 6)/* can support */ +#define MMC_CAP2_MAX_DISCARD_SIZE (1 << 8)/* use max discard, ignoring max_busy_timeout parameter */ #define MMC_CAP2_HS200 (MMC_CAP2_HS200_1_8V_SDR | \ MMC_CAP2_HS200_1_2V_SDR)#define MMC_CAP2_CD_ACTIVE_HIGH (1 << 10)/* Card-detect signal active high */ --The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 2/9 mmc: core: allow hosts to specify a large discard size
In reply to Bao D. NguyenFrom: Ziqi Chen <[email protected]>
max_busy_timeout is used to decide whether R1B response should be used or a R1 response should be used. This is also used to decide what the discard size of mmc queue (registered with block layer) can be set to. In order to keep both the features in place, this change will allow for hosts to specify a larger discard size while still specifying max_busy_timeout.
--- drivers/mmc/core/core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/mmc/core/core.c +4 -0
@@ -2059,6 +2059,10 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card)struct mmc_host *host = card->host;unsigned int max_discard, max_trim; +if (!host->max_busy_timeout || + (host->caps2 &MMC_CAP2_MAX_DISCARD_SIZE )) +return UINT_MAX ; +/* * Without erase_group_def set, MMC erase timeout depends on clock * frequence which can change. In that case, the best choice is
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 3/9 mmc: host: Add device_prepare pm for mmc_host
In reply to Bao D. NguyenFrom: Vijay Viswanath <[email protected]>
mmc_host is a virtual device and it doesn't have any pm ops and so during pm registration of device, no_pm_callback gets set as true. The mmc_host device is not runtime enabled as it is a virtual device and mmc_host is the parent device of mmc_card. As the mmc_host is runtime disabled, mmc_card can runtime suspend/resume without depending on state of mmc_host during normal operations. During system suspend, the direct_complete flag of mmc_host device gets set as it has no pm_ops. When mmc_card successfully suspends, it clears the direct_complete flag of its parent (mmc_host).
But in certain cases during dpm_suspend, an async error can occur after suspend work for mmc_card is scheduled and before it gets executed. In that case, mmc_card suspend work will not clear the direct_complete flag of mmc_host. When mmc_host suspend comes after that of mmc_card, it too will skip all actions.
But by this time, the mmc_host device has been added to device_suspended list. So during resume, mmc_host resume will do dpm resume of mmc_host. In dpm_resume, all devices which has direct_complete flag set will be runtime_enabled. This is because, in dpm_suspend, any device with direct_complete flag will be runtime_disabled. Thus, mmc_host which has direct_complete flag set, will get runtime enabled during dpm_resume. This is a problem in pm framework with direct_complete flag (runtime enabling a device in resume when it was not runtime disabled in suspend path).
Now that mmc_host device is runtime enabled, to runtime resume the mmc_card, the pm framework will try to runtime resume the mmc_host device as well and will fail. This prevents mmc_card from runtime resuming after a runtime_suspend.
Fix this by adding a dummy suspend_prepare() fn for mmc_host. This prevents the direct_complete flag of mmc_host device from getting set.
--- drivers/mmc/core/host.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/mmc/core/host.c +19 -0
@@ -40,9 +40,28 @@ static void mmc_host_classdev_release(struct device *dev)kfree (host); } +static int mmc_host_prepare (struct device *dev) +{ +/* +* Since mmc_host is a virtual device, we don't have to do anything. +* If we return a positive value, the pm framework will consider that +* the runtime suspend and system suspend of this device is same and +* will set direct_complete flag as true. We don't want this as the +* mmc_host always has positive disable_depth and setting the flag +* will not speed up the suspend process. +* So return 0. +*/ +return 0 ; +} + +static const struct dev_pm_ops mmc_pm_ops = { + .prepare = mmc_host_prepare, +}; +static struct class mmc_host_class = { .name ="mmc_host" , .dev_release = mmc_host_classdev_release, + .pm = &mmc_pm_ops, };int mmc_register_host_class (void )
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 4/9 mmc: core: fix SD card request queue refcount underflow during shutdown
In reply to Bao D. NguyenFrom: Can Guo <[email protected]>
When system shutdown, kernel shall call shutdown function of mmc to stop its request queue and clean it up, during which the request queue's kobject shall be put once. In normal cases, if the SD card is removed, the mmc_blk_remove routine releases all the resources and kobjects related to the disk and request queue by decreasing their kref counts to 0. But if the SD card is removed after its shutdown function is called, below kref count underflow error shall be thrown out because the kref count was decreased once during request queue cleanup by the shutdown function in advance. This change fixes it by skipping request queue cleanup in the mmc blk routine if the queue has been marked as dead.
[ 166.187211] refcount_t: underflow; use-after-free. [ 166.187277] ------------[ cut here ]------------ [ 166.187321] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP [ 166.187542] Workqueue: events_freezable mmc_rescan [ 166.187558] task: ffffffe673b96680 task.stack: ffffff8008418000 [ 166.187579] pc : refcount_sub_and_test+0x64/0x78 [ 166.187593] lr : refcount_sub_and_test+0x64/0x78 [ 166.187605] sp : ffffff800841ba20 pstate : 60c00145 [ 166.188319] Call trace: [ 166.188331] refcount_sub_and_test+0x64/0x78 [ 166.188343] refcount_dec_and_test+0x18/0x24 [ 166.188355] kobject_put+0x5c/0x74 [ 166.188374] blk_put_queue+0x1c/0x28 [ 166.188388] disk_release+0x70/0x90 [ 166.188402] device_release+0x38/0x90 [ 166.188429] kobject_cleanup+0xc4/0x1c0 [ 166.188441] kobject_put+0x68/0x74 [ 166.188455] put_disk+0x20/0x2c [ 166.188467] mmc_blk_put+0x9c/0xdc [ 166.188480] mmc_blk_remove_req+0x110/0x120 [ 166.188493] mmc_blk_remove+0x14c/0x22c [ 166.188505] mmc_bus_remove+0x24/0x34 [ 166.188517] device_release_driver_internal+0x13c/0x1e0 [ 166.188528] device_release_driver+0x24/0x30 [ 166.188540] bus_remove_device+0xdc/0x120 [ 166.188552] device_del+0x1e0/0x284 [ 166.188564] mmc_remove_card+0x68/0x7c [ 166.188577] mmc_sd_remove+0x24/0x48 [ 166.188588] mmc_sd_detect+0x120/0x1a4 [ 166.188600] mmc_rescan+0xf4/0x384 [ 166.188613] process_one_work+0x1c0/0x3d4 [ 166.188625] worker_thread+0x224/0x344 [ 166.188637] kthread+0x120/0x130 [ 166.188649] ret_from_fork+0x10/0x18.
--- drivers/mmc/core/queue.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/core/queue.c +2 -1
@@ -506,7 +506,8 @@ void mmc_cleanup_queue(struct mmc_queue *mq)if (blk_queue_quiesced (q))blk_mq_unquiesce_queue (q); -blk_cleanup_queue (q); +if (likely (!blk_queue_dead (q))) +blk_cleanup_queue (q);blk_mq_free_tag_set (&mq->tag_set);/*
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [<PATCH v1> 4/9] mmc: core: fix SD card request queue refcount underflow during shutdown
Quoted 60 lines · Bao D. Nguyen
From: Can Guo <[email protected]>
When system shutdown, kernel shall call shutdown function of mmc to stop its request queue and clean it up, during which the request queue's kobject shall be put once. In normal cases, if the SD card is removed, the
mmc_blk_removeroutine releases all the resources and kobjects related to the disk and request queue by decreasing their kref counts to 0. But if the SD card is removed after its shutdown function is called, below kref count underflow error shall be thrown out because the kref count was decreased once during request queue cleanup by the shutdown function in advance. This change fixes it by skipping request queue cleanup in the mmc blk routine if the queue has been marked as dead.[ 166.187211] refcount_t: underflow; use-after-free. [ 166.187277] ------------[ cut here ]------------ [ 166.187321] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP [ 166.187542] Workqueue: events_freezable mmc_rescan [ 166.187558] task: ffffffe673b96680 task.stack: ffffff8008418000 [ 166.187579] pc : refcount_sub_and_test+0x64/0x78 [ 166.187593] lr : refcount_sub_and_test+0x64/0x78 [ 166.187605] sp : ffffff800841ba20 pstate : 60c00145 [ 166.188319] Call trace: [ 166.188331] refcount_sub_and_test+0x64/0x78 [ 166.188343] refcount_dec_and_test+0x18/0x24 [ 166.188355] kobject_put+0x5c/0x74 [ 166.188374] blk_put_queue+0x1c/0x28 [ 166.188388] disk_release+0x70/0x90 [ 166.188402] device_release+0x38/0x90 [ 166.188429] kobject_cleanup+0xc4/0x1c0 [ 166.188441] kobject_put+0x68/0x74 [ 166.188455] put_disk+0x20/0x2c [ 166.188467] mmc_blk_put+0x9c/0xdc [ 166.188480] mmc_blk_remove_req+0x110/0x120 [ 166.188493] mmc_blk_remove+0x14c/0x22c [ 166.188505] mmc_bus_remove+0x24/0x34 [ 166.188517] device_release_driver_internal+0x13c/0x1e0 [ 166.188528] device_release_driver+0x24/0x30 [ 166.188540] bus_remove_device+0xdc/0x120 [ 166.188552] device_del+0x1e0/0x284 [ 166.188564] mmc_remove_card+0x68/0x7c [ 166.188577] mmc_sd_remove+0x24/0x48 [ 166.188588] mmc_sd_detect+0x120/0x1a4 [ 166.188600] mmc_rescan+0xf4/0x384 [ 166.188613] process_one_work+0x1c0/0x3d4 [ 166.188625] worker_thread+0x224/0x344 [ 166.188637] kthread+0x120/0x130 [ 166.188649] ret_from_fork+0x10/0x18.Signed-off-by Can Guo <[email protected]>Signed-off-by Sayali Lokhande <[email protected]>Signed-off-by Bao D. Nguyen <[email protected]>--- drivers/mmc/core/queue.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/mmc/core/queue.c +0
-0
drivers/mmc/core/queue.c void mmc_cleanup_queue(struct mmc_queue *mq) · line 510
Quoted 6 lines
drivers/mmc/core/queue.c +2
-1@@ -506,7 +506,8 @@ void mmc_cleanup_queue(struct mmc_queue *mq)if (blk_queue_quiesced (q))blk_mq_unquiesce_queue (q); -blk_cleanup_queue (q); +if (likely (!blk_queue_dead (q))) +blk_cleanup_queue (q);
Unless you can measure the performance impact, never use unlikely/likely in kernel code. The compiler and cpu will always do much better over time than you can.
That being said, what will cleanup the queue if it is not "dead" at this point in time, later on? Isn't this a leak?
thanks,
greg k-h
PATCH 5/9 mmc: core: fix one NULL pointer dereference after SD card is removed
In reply to Bao D. NguyenFrom: Can Guo <[email protected]>
After SD card is removed, the driver would mark its queue DYING to try to block further more requests from coming into the queue, then clean up its queue's queuedata by setting it to NULL. However, there can still be new requests come in right before the DYING mark is set after SD card is removed. When one new request is allocated and initialized, the queuedata would be accessed. If queuedata has been cleaned up already, NULL pointer dereference would happen. This change fixes it by checking if queuedata is NULL before accessing it, if yes, then bails out with error.
mmc0: card aaaa removed
Buffer I/O error on dev mmcblk0p1, logical block 1, lost async page write
Unable to handle kernel NULL pointer dereference at virtual address
00000000
Mem abort info:
Exception class = DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
Data abort info:
ISV = 0, ISS = 0x00000006
CM = 0, WnR = 0
user pgtable: 4k pages, 39-bit VAs, pgd = ffffffd7bbafa000 [0000000000000000] *pgd=0000000134331003, *pud=0000000134331003, *pmd=0000000000000000
Internal error: Oops: 96000006 [#1] PREEMPT SMP task: ffffffd77d193380 task.stack: ffffff8047e30000 pc : mmc_init_request+0x28/0x74 lr : alloc_request_size+0x4c/0x70 ... Process MediaScannerSer (pid: 4710, stack limit = 0xffffff8047e30000) Call trace: mmc_init_request+0x28/0x74 alloc_request_size+0x4c/0x70 mempool_alloc+0x104/0x184 get_request+0x324/0x75c blk_queue_bio+0x154/0x398 generic_make_request+0xcc/0x228 submit_bio+0x13c/0x1d4.
--- drivers/mmc/core/queue.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/mmc/core/queue.c +5 -2
@@ -211,8 +211,11 @@ static int __mmc_init_request(struct mmc_queue *mq, struct request *req, gfp_t gfp) {struct mmc_queue_req *mq_rq =req_to_mmc_queue_req (req); -struct mmc_card *card = mq->card; -struct mmc_host *host = card->host; +struct mmc_host *host; + +if (!mq) +return -ENODEV ; + host = mq->card->host; mq_rq->sg =mmc_alloc_sg (mmc_get_max_segments (host), gfp);if (!mq_rq->sg)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 6/9 mmc: sdhci-msm: Ignore data timeout error for R1B commands
In reply to Bao D. NguyenFrom: Sahitya Tummala <[email protected]>
Ignore data timeout error for R1B commands as there will be no data associated and the busy timeout value for these commands could be lager than the maximum timeout value that controller can handle.
--- drivers/mmc/host/sdhci.c | 15 +++++++++------ drivers/mmc/host/sdhci.h | 7 +++++++ 2 files changed, 16 insertions(+), 6 deletions(-)
drivers/mmc/host/sdhci.c +9 -6
@@ -2925,12 +2925,6 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)* above in sdhci_cmd_irq(). */ if (data_cmd && (data_cmd->flags &MMC_RSP_BUSY )) { -if (intmask &SDHCI_INT_DATA_TIMEOUT ) { - host->data_cmd =NULL ; - data_cmd->error = -ETIMEDOUT ; -__sdhci_finish_mrq (host, data_cmd->mrq); -return ; - }if (intmask &SDHCI_INT_DATA_END ) { host->data_cmd =NULL ;/*
@@ -2944,6 +2938,15 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)__sdhci_finish_mrq (host, data_cmd->mrq);return ; } +if (host->quirks2 & +SDHCI_QUIRK2_IGNORE_DATATOUT_FOR_R1BCMD ) +return ; +if (intmask &SDHCI_INT_DATA_TIMEOUT ) { + host->data_cmd =NULL ; + data_cmd->error = -ETIMEDOUT ; +__sdhci_finish_mrq (host, data_cmd->mrq); +return ; + } }/*
drivers/mmc/host/sdhci.h +7 -0
@@ -482,6 +482,13 @@ struct sdhci_host {* block count. */ #define SDHCI_QUIRK2_USE_32BIT_BLK_CNT (1<<18) +/* +* Ignore data timeout error for R1B commands as there will be no +* data associated and the busy timeout value for these commands +* could be lager than the maximum timeout value that controller +* can handle. +*/ +#define SDHCI_QUIRK2_IGNORE_DATATOUT_FOR_R1BCMD (1<<19)int irq;/* Device IRQ */ void __iomem *ioaddr;/* Mapped address */
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [<PATCH v1> 6/9] mmc: sdhci-msm: Ignore data timeout error for R1B commands
Quoted 52 lines · Bao D. Nguyen
From: Sahitya Tummala <[email protected]>
Ignore data timeout error for R1B commands as there will be no data associated and the busy timeout value for these commands could be lager than the maximum timeout value that controller can handle.
Signed-off-by Sahitya Tummala <[email protected]>Signed-off-by Bao D. Nguyen <[email protected]>--- drivers/mmc/host/sdhci.c | 15 +++++++++------ drivers/mmc/host/sdhci.h | 7 +++++++ 2 files changed, 16 insertions(+), 6 deletions(-)drivers/mmc/host/sdhci.c +9
-6@@ -2925,12 +2925,6 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)* above in sdhci_cmd_irq(). */ if (data_cmd && (data_cmd->flags &MMC_RSP_BUSY )) { -if (intmask &SDHCI_INT_DATA_TIMEOUT ) { - host->data_cmd =NULL ; - data_cmd->error = -ETIMEDOUT ; -__sdhci_finish_mrq (host, data_cmd->mrq); -return ; - }if (intmask &SDHCI_INT_DATA_END ) { host->data_cmd =NULL ;/* @@ -2944,6 +2938,15 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)__sdhci_finish_mrq (host, data_cmd->mrq);return ; } +if (host->quirks2 & +SDHCI_QUIRK2_IGNORE_DATATOUT_FOR_R1BCMD ) +return ; +if (intmask &SDHCI_INT_DATA_TIMEOUT ) { + host->data_cmd =NULL ; + data_cmd->error = -ETIMEDOUT ; +__sdhci_finish_mrq (host, data_cmd->mrq); +return ; + } }/* drivers/mmc/host/sdhci.h +0
-0
drivers/mmc/host/sdhci.h struct sdhci_host { · line 491
Quoted 10 lines
drivers/mmc/host/sdhci.h +7
-0@@ -482,6 +482,13 @@ struct sdhci_host {* block count. */ #define SDHCI_QUIRK2_USE_32BIT_BLK_CNT (1<<18) +/* +* Ignore data timeout error for R1B commands as there will be no +* data associated and the busy timeout value for these commands +* could be lager than the maximum timeout value that controller +* can handle. +*/ +#define SDHCI_QUIRK2_IGNORE_DATATOUT_FOR_R1BCMD (1<<19)
No tabs?
And what about using BIT(19) instead?
thanks,
greg k-h
PATCH 7/9 mmc: core: Skip frequency retries for SDCC slots
In reply to Bao D. NguyenFrom: Sujith Reddy Thumma <[email protected]>
Qualcomm SDCC controller supports minimum SD clock frequency which is required for card initialization. This information is exported through platform data for each SDCC controller. There is no need of retrying higher frequencies than the minimum supported by controller for Qualcomm chipsets which inturn add delay in detection process if there is no card during suspend/resume cycles. Hence, skip multiple frequency retries.
--- drivers/mmc/core/core.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/mmc/core/core.c +1 -8
@@ -2281,7 +2281,6 @@ void mmc_rescan(struct work_struct *work) {struct mmc_host *host = container_of(work, struct mmc_host, detect.work); -int i;if (host->rescan_disable)return ;
@@ -2332,13 +2331,7 @@ void mmc_rescan(struct work_struct *work)mmc_release_host (host); goto out; } - -for (i =0 ; i <ARRAY_SIZE (freqs); i++) { -if (!mmc_rescan_try_freq (host,max (freqs[i], host->f_min))) -break ; -if (freqs[i] <= host->f_min) -break ; - } +mmc_rescan_try_freq (host, host->f_min);mmc_release_host (host); out:
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [<PATCH v1> 7/9] mmc: core: Skip frequency retries for SDCC slots
Quoted 32 lines · Bao D. Nguyen
From: Sujith Reddy Thumma <[email protected]>
Qualcomm SDCC controller supports minimum SD clock frequency which is required for card initialization. This information is exported through platform data for each SDCC controller. There is no need of retrying higher frequencies than the minimum supported by controller for Qualcomm chipsets which inturn add delay in detection process if there is no card during suspend/resume cycles. Hence, skip multiple frequency retries.
Signed-off-by Sujith Reddy Thumma <[email protected]>Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Xiaonian Wang <[email protected]>Signed-off-by Bao D. Nguyen <[email protected]>--- drivers/mmc/core/core.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)drivers/mmc/core/core.c +0
-1@@ -2281,7 +2281,6 @@ void mmc_rescan(struct work_struct *work) {struct mmc_host *host = container_of(work, struct mmc_host, detect.work); -int i;if (host->rescan_disable)return ;@@ -2332,13 +2331,7 @@ void mmc_rescan(struct work_struct *work)mmc_release_host (host);
drivers/mmc/core/core.c void mmc_rescan(struct work_struct *work) · line 2334
Quoted 10 lines
drivers/mmc/core/core.c +1
-7goto out; } - -for (i =0 ; i <ARRAY_SIZE (freqs); i++) { -if (!mmc_rescan_try_freq (host,max (freqs[i], host->f_min))) -break ; -if (freqs[i] <= host->f_min) -break ; - } +mmc_rescan_try_freq (host, host->f_min);
What about for non-qualcomm controllers? Did this just break their functionality?
thanks,
greg k-h
Re: [<PATCH v1> 7/9] mmc: core: Skip frequency retries for SDCC slots
Quoted 39 lines · Greg KH
Quoted 37 lines · Bao D. Nguyen
From: Sujith Reddy Thumma <[email protected]>
Qualcomm SDCC controller supports minimum SD clock frequency which is required for card initialization. This information is exported through platform data for each SDCC controller. There is no need of retrying higher frequencies than the minimum supported by controller for Qualcomm chipsets which inturn add delay in detection process if there is no card during suspend/resume cycles. Hence, skip multiple frequency retries.
Signed-off-by Sujith Reddy Thumma <[email protected]>Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Xiaonian Wang <[email protected]>Signed-off-by Bao D. Nguyen <[email protected]>--- drivers/mmc/core/core.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)drivers/mmc/core/core.c +0
-4@@ -2281,7 +2281,6 @@ void mmc_rescan(struct work_struct *work) {struct mmc_host *host = container_of(work, struct mmc_host, detect.work); -int i;if (host->rescan_disable)return ;@@ -2332,13 +2331,7 @@ void mmc_rescan(struct work_struct *work)mmc_release_host (host); goto out; } - -for (i =0 ; i <ARRAY_SIZE (freqs); i++) { -if (!mmc_rescan_try_freq (host,max (freqs[i], host->f_min)))
Quoted 8 lines
drivers/mmc/core/core.c void mmc_rescan(struct work_struct *work) · line 2334
Quoted 5 lines
drivers/mmc/core/core.c +1
-4-break ; -if (freqs[i] <= host->f_min) -break ; - } +mmc_rescan_try_freq (host, host->f_min);What about for non-qualcomm controllers? Did this just break their functionality?
Yes it does, obviously.
Greg, thanks for providing some valuable feedback for Bao for a couple of the patches in this series.
I have also browsed through the series, but stopped providing feedback after patch1, when I realized that these are all just downstream vendor specific hacks.
Sure, I guess most of the patches can be reworked as upstreamable solutions, but rather than looking at them all at once, please post them separately. Additionally, in general I would appreciate more details in the changelogs to fully understand the problems your are solving.
Kind regards
Uffe
Re: [<PATCH v1> 7/9] mmc: core: Skip frequency retries for SDCC slots
Quoted 49 lines · Ulf Hansson
Quoted 39 lines · Greg KH
Quoted 37 lines · Bao D. Nguyen
From: Sujith Reddy Thumma <[email protected]>
Qualcomm SDCC controller supports minimum SD clock frequency which is required for card initialization. This information is exported through platform data for each SDCC controller. There is no need of retrying higher frequencies than the minimum supported by controller for Qualcomm chipsets which inturn add delay in detection process if there is no card during suspend/resume cycles. Hence, skip multiple frequency retries.
Signed-off-by Sujith Reddy Thumma <[email protected]>Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Xiaonian Wang <[email protected]>Signed-off-by Bao D. Nguyen <[email protected]>--- drivers/mmc/core/core.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)drivers/mmc/core/core.c +0
-4@@ -2281,7 +2281,6 @@ void mmc_rescan(struct work_struct *work) {struct mmc_host *host = container_of(work, struct mmc_host, detect.work); -int i;if (host->rescan_disable)return ;@@ -2332,13 +2331,7 @@ void mmc_rescan(struct work_struct *work)mmc_release_host (host); goto out; } - -for (i =0 ; i <ARRAY_SIZE (freqs); i++) { -if (!mmc_rescan_try_freq (host,max (freqs[i], host->f_min)))Quoted 8 lines
drivers/mmc/core/core.c void mmc_rescan(struct work_struct *work) · line 2334
Quoted 5 lines
drivers/mmc/core/core.c +1
-4-break ; -if (freqs[i] <= host->f_min) -break ; - } +mmc_rescan_try_freq (host, host->f_min);What about for non-qualcomm controllers? Did this just break their functionality?
Quoted 8 lines
Yes it does, obviously.
Greg, thanks for providing some valuable feedback for Bao for a couple of the patches in this series.
I have also browsed through the series, but stopped providing feedback after patch1, when I realized that these are all just downstream vendor specific hacks.
That's all kernel drivers are, vendor-specific quirks/hacks around broken hardware :)
Splitting this out into logical fixes, like some of these are here, is great. But breaking non-qualcomm hardware like this patch would do, is obviously not ok.
Quoted 2 lines
Sure, I guess most of the patches can be reworked as upstreamable solutions,
They have to be upstreamable, you don't want these in random vendor trees as they go no where and atrophy and break users. We want them in our main tree for everyone to use for the obvious reason that they are needed to get real hardware working.
thanks,
greg k-h
Re: [<PATCH v1> 7/9] mmc: core: Skip frequency retries for SDCC slots
Quoted 67 lines · Greg Kroah-Hartman
Quoted 49 lines · Ulf Hansson
Quoted 39 lines · Greg KH
Quoted 37 lines · Bao D. Nguyen
From: Sujith Reddy Thumma <[email protected]>
Qualcomm SDCC controller supports minimum SD clock frequency which is required for card initialization. This information is exported through platform data for each SDCC controller. There is no need of retrying higher frequencies than the minimum supported by controller for Qualcomm chipsets which inturn add delay in detection process if there is no card during suspend/resume cycles. Hence, skip multiple frequency retries.
Signed-off-by Sujith Reddy Thumma <[email protected]>Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Xiaonian Wang <[email protected]>Signed-off-by Bao D. Nguyen <[email protected]>--- drivers/mmc/core/core.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)drivers/mmc/core/core.c +0
-4@@ -2281,7 +2281,6 @@ void mmc_rescan(struct work_struct *work) {struct mmc_host *host = container_of(work, struct mmc_host, detect.work); -int i;if (host->rescan_disable)return ;@@ -2332,13 +2331,7 @@ void mmc_rescan(struct work_struct *work)mmc_release_host (host); goto out; } - -for (i =0 ; i <ARRAY_SIZE (freqs); i++) { -if (!mmc_rescan_try_freq (host,max (freqs[i], host->f_min)))Quoted 8 lines
drivers/mmc/core/core.c void mmc_rescan(struct work_struct *work) · line 2334
Quoted 5 lines
drivers/mmc/core/core.c +1
-4-break ; -if (freqs[i] <= host->f_min) -break ; - } +mmc_rescan_try_freq (host, host->f_min);What about for non-qualcomm controllers? Did this just break their functionality?
Quoted 8 lines
Yes it does, obviously.
Greg, thanks for providing some valuable feedback for Bao for a couple of the patches in this series.
I have also browsed through the series, but stopped providing feedback after patch1, when I realized that these are all just downstream vendor specific hacks.
That's all kernel drivers are, vendor-specific quirks/hacks around broken hardware :)
Splitting this out into logical fixes, like some of these are here, is great. But breaking non-qualcomm hardware like this patch would do, is obviously not ok.
Quoted 7 lines
Quoted 2 lines
Sure, I guess most of the patches can be reworked as upstreamable solutions,
They have to be upstreamable, you don't want these in random vendor trees as they go no where and atrophy and break users. We want them in our main tree for everyone to use for the obvious reason that they are needed to get real hardware working.
I fully agree and I am willing to help!
Just didn't want to waste my time reviewing all at once in great detail - if it turns out that the submitter don't care to re-spin, as that has happened before (not by Bao).
Kind regards
Uffe
PATCH 8/9 mmc: core: remove shutdown handler
In reply to Bao D. NguyenFrom: Subhash Jadavani <[email protected]>
If mmc/sd shutdown callback suspends the card when card's runtime PM status is still set to "runtime active" then any request issued after mmc/sd shutdown will not resume the card hence we will end up issuing the request to host driver while card isn't in a state to handle it.
Right way to fix this issue is not to allow any requests to flow in after the shutdown callback has executed. Until it is fixed in the right way, we are disabling the shutdown handling as it anyways doesn't do real useful things.
--- drivers/mmc/core/mmc.c | 22 ---------------------- drivers/mmc/core/sd.c | 1 - 2 files changed, 23 deletions(-)
drivers/mmc/core/mmc.c +0 -22
@@ -2080,27 +2080,6 @@ static int _mmc_resume(struct mmc_host *host) }/* -* Shutdown callback -*/ -static int mmc_shutdown (struct mmc_host *host) -{ -int err =0 ; - -/* -* In a specific case for poweroff notify, we need to resume the card -* before we can shutdown it properly. -*/ -if (mmc_can_poweroff_notify (host->card) && - !(host->caps2 &MMC_CAP2_FULL_PWR_CYCLE )) - err =_mmc_resume (host); - -if (!err) - err =_mmc_suspend (host, false); - -return err; -} - -/* * Callback for resume. */ static int mmc_resume (struct mmc_host *host)
@@ -2185,7 +2164,6 @@ static int _mmc_hw_reset(struct mmc_host *host) .runtime_suspend = mmc_runtime_suspend, .runtime_resume = mmc_runtime_resume, .alive = mmc_alive, - .shutdown = mmc_shutdown, .hw_reset = _mmc_hw_reset, };
drivers/mmc/core/sd.c +0 -1
@@ -1259,7 +1259,6 @@ static int mmc_sd_hw_reset(struct mmc_host *host) .suspend = mmc_sd_suspend, .resume = mmc_sd_resume, .alive = mmc_sd_alive, - .shutdown = mmc_sd_suspend, .hw_reset = mmc_sd_hw_reset, };
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 9/9 mmc: sd: Fix trivial SD card issues
In reply to Bao D. NguyenFrom: "Bao D. Nguyen" <[email protected]>
Fix various trivial SD card issues.
--- drivers/mmc/core/block.c | 4 ++-- drivers/mmc/core/bus.c | 13 +++++++++++++ drivers/mmc/core/core.c | 13 ++++++++----- drivers/mmc/core/sd.c | 9 ++++++--- 4 files changed, 29 insertions(+), 10 deletions(-)
drivers/mmc/core/block.c +2 -2
@@ -653,13 +653,13 @@ static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md,struct request *req; idata =mmc_blk_ioctl_copy_from_user (ic_ptr); -if (IS_ERR (idata)) +if (IS_ERR_OR_NULL (idata))return PTR_ERR (idata);/* This will be NULL on non-RPMB ioctl():s */ idata->rpmb = rpmb; card = md->queue.card; -if (IS_ERR (card)) { +if (IS_ERR_OR_NULL (card)) { err =PTR_ERR (card); goto cmd_done; }
drivers/mmc/core/bus.c +13 -0
@@ -131,6 +131,16 @@ static void mmc_bus_shutdown(struct device *dev)struct mmc_host *host = card->host;int ret; +if (!drv) { +pr_debug ("%s: %s: drv is NULL\n" ,dev_name (dev), __func__); +return ; + } + +if (!card) { +pr_debug ("%s: %s: card is NULL\n" ,dev_name (dev), __func__); +return ; + } +if (dev->driver && drv->shutdown) drv->shutdown (card);
@@ -247,12 +257,15 @@ void mmc_unregister_driver(struct mmc_driver *drv)static void mmc_release_card (struct device *dev) {struct mmc_card *card =mmc_dev_to_card (dev); +struct mmc_host *host = card->host;sdio_free_common_cis (card);kfree (card->info);kfree (card); +if (host) + host->card =NULL ; }/*
drivers/mmc/core/core.c +8 -5
@@ -399,7 +399,7 @@ void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq)struct mmc_command *cmd;while (1 ) { -wait_for_completion (&mrq->completion); +wait_for_completion_io (&mrq->completion); cmd = mrq->cmd;
@@ -666,6 +666,10 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card) {unsigned int mult; +if (!card) { +WARN_ON (1 ); +return ; + }/* * SDIO cards only define an upper 1 s limit on access. */
@@ -2341,17 +2345,16 @@ void mmc_rescan(struct work_struct *work)void mmc_start_host (struct mmc_host *host) { +mmc_claim_host (host); host->f_init =max (freqs[0 ], host->f_min); host->rescan_disable =0 ; host->ios.power_mode =MMC_POWER_UNDEFINED ; -if (!(host->caps2 &MMC_CAP2_NO_PRESCAN_POWERUP )) { -mmc_claim_host (host); +if (!(host->caps2 &MMC_CAP2_NO_PRESCAN_POWERUP ))mmc_power_up (host, host->ocr_avail); -mmc_release_host (host); - }mmc_gpiod_request_cd_irq (host); +mmc_release_host (host);_mmc_detect_change (host,0 , false); }
drivers/mmc/core/sd.c +6 -3
@@ -989,6 +989,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, err =mmc_send_relative_addr (host, &card->rca);if (err) goto free_card; + host->card = card; }if (!oldcard) {
@@ -1090,13 +1091,13 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, goto free_card; } done: - host->card = card;return 0 ; free_card: -if (!oldcard) +if (!oldcard) { + host->card =NULL ;mmc_remove_card (card); - + }return err; }
@@ -1106,7 +1107,9 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,static void mmc_sd_remove (struct mmc_host *host) {mmc_remove_card (host->card); +mmc_claim_host (host); host->card =NULL ; +mmc_release_host (host); }/*
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [<PATCH v1> 9/9] mmc: sd: Fix trivial SD card issues
Quoted 3 lines · Bao D. Nguyen
From: "Bao D. Nguyen" <[email protected]>
Fix various trivial SD card issues.
There are a number of real bugfixes in here, please split these out and put them at the beginning of the series so that they can be backported to the stable kernel tree. Specifics below:
Quoted 14 lines
Signed-off-by Bao D. Nguyen <[email protected]>--- drivers/mmc/core/block.c | 4 ++-- drivers/mmc/core/bus.c | 13 +++++++++++++ drivers/mmc/core/core.c | 13 ++++++++----- drivers/mmc/core/sd.c | 9 ++++++--- 4 files changed, 29 insertions(+), 10 deletions(-)drivers/mmc/core/block.c +0
-0
drivers/mmc/core/block.c static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md, · line 656
Quoted 5 lines
drivers/mmc/core/block.c +1
-1@@ -653,13 +653,13 @@ static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md,struct request *req; idata =mmc_blk_ioctl_copy_from_user (ic_ptr); -if (IS_ERR (idata)) +if (IS_ERR_OR_NULL (idata))
How can this function ever return NULL?
drivers/mmc/core/block.c static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md, · line 657
Quoted 1 line
drivers/mmc/core/block.c +0
-0return PTR_ERR (idata);
If NULL was returned, are you sure you can return 0 here? That implies that all went well, when obviously it did not.
But again, I do not see how mmc_blk_ioctl_copy_from_user() can return NULL, do you?
drivers/mmc/core/block.c static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md, · line 662
Quoted 6 lines
drivers/mmc/core/block.c +1
-1/* This will be NULL on non-RPMB ioctl():s */ idata->rpmb = rpmb; card = md->queue.card; -if (IS_ERR (card)) { +if (IS_ERR_OR_NULL (card)) {
How can card be NULL?
drivers/mmc/core/block.c static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md, · line 663
Quoted 1 line
drivers/mmc/core/block.c +0
-0err =PTR_ERR (card);
Again, returning "success" is ok? Are you sure?
drivers/mmc/core/bus.c static void mmc_bus_shutdown(struct device *dev) · line 135
Quoted 12 lines
drivers/mmc/core/block.c +0
-0goto cmd_done; }drivers/mmc/core/bus.c +2
-0@@ -131,6 +131,16 @@ static void mmc_bus_shutdown(struct device *dev)struct mmc_host *host = card->host;int ret; +if (!drv) { +pr_debug ("%s: %s: drv is NULL\n" ,dev_name (dev), __func__);
How can this ever happen?
And never use pr_* calls in a driver, you have a valid device, use dev_dbg() and friends.
drivers/mmc/core/bus.c static void mmc_bus_shutdown(struct device *dev) · line 140
Quoted 5 lines
drivers/mmc/core/bus.c +5
-0+return ; + } + +if (!card) { +pr_debug ("%s: %s: card is NULL\n" ,dev_name (dev), __func__);
Same here, how can this ever happen?
Quoted 9 lines
drivers/mmc/core/bus.c +3
-0+return ; + } +if (dev->driver && drv->shutdown) drv->shutdown (card);@@ -247,12 +257,15 @@ void mmc_unregister_driver(struct mmc_driver *drv)static void mmc_release_card (struct device *dev) {
drivers/mmc/core/bus.c void mmc_unregister_driver(struct mmc_driver *drv) · line 268
Quoted 10 lines
drivers/mmc/core/bus.c +3
-0struct mmc_card *card =mmc_dev_to_card (dev); +struct mmc_host *host = card->host;sdio_free_common_cis (card);kfree (card->info);kfree (card); +if (host) + host->card =NULL ;
Why are you setting this to null? Does this solve some race condition that you are then catching in the shutdown callback? If so, this should be broken out as a separate bugfix and put earlier in the series as that should go to all stable kernels, right?
drivers/mmc/core/core.c void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq) · line 402
Quoted 13 lines
drivers/mmc/core/bus.c +0
-0}/* drivers/mmc/core/core.c +1
-1@@ -399,7 +399,7 @@ void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq)struct mmc_command *cmd;while (1 ) { -wait_for_completion (&mrq->completion); +wait_for_completion_io (&mrq->completion);
Why this change? That seems like a big one. Why is this not a separate patch?
drivers/mmc/core/core.c void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card) · line 670
Quoted 9 lines
drivers/mmc/core/core.c +2
-0cmd = mrq->cmd;@@ -666,6 +666,10 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card) {unsigned int mult; +if (!card) { +WARN_ON (1 );
And you just crashed systems that run with panic-on-warn :(
How can this ever happen? If it is a real issue, catch it, log it, and then move on, don't splat the kernel log with a full traceback and reboot machines :(
drivers/mmc/core/core.c void mmc_rescan(struct work_struct *work) · line 2348
Quoted 10 lines
drivers/mmc/core/core.c +3
-0+return ; + }/* * SDIO cards only define an upper 1 s limit on access. */ @@ -2341,17 +2345,16 @@ void mmc_rescan(struct work_struct *work)void mmc_start_host (struct mmc_host *host) { +mmc_claim_host (host);
What? This is a totally separate change, plaese break this out and describe what you are fixing here. Again, should be a bugfix for earlier in the series.
drivers/mmc/core/core.c void mmc_rescan(struct work_struct *work) · line 2357
Quoted 13 lines
drivers/mmc/core/core.c +2
-4host->f_init =max (freqs[0 ], host->f_min); host->rescan_disable =0 ; host->ios.power_mode =MMC_POWER_UNDEFINED ; -if (!(host->caps2 &MMC_CAP2_NO_PRESCAN_POWERUP )) { -mmc_claim_host (host); +if (!(host->caps2 &MMC_CAP2_NO_PRESCAN_POWERUP ))mmc_power_up (host, host->ocr_avail); -mmc_release_host (host); - }mmc_gpiod_request_cd_irq (host); +mmc_release_host (host);
And are you sure the reference counting is correct here? Before this patch, you dropped the reference above, now you are matching it. Either this is wrong, or the original code is wrong. Either way, you need to describe it much better please.
drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, · line 992
Quoted 12 lines
drivers/mmc/core/core.c +0
-0_mmc_detect_change (host,0 , false); }drivers/mmc/core/sd.c +1
-0@@ -989,6 +989,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, err =mmc_send_relative_addr (host, &card->rca);if (err) goto free_card; + host->card = card;
Why?
Quoted 4 lines
drivers/mmc/core/sd.c +0
-0}if (!oldcard) {
drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, · line 1098
Quoted 10 lines
drivers/mmc/core/sd.c +2
-2@@ -1090,13 +1091,13 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, goto free_card; } done: - host->card = card;return 0 ; free_card: -if (!oldcard) +if (!oldcard) { + host->card =NULL ;
Again, why?
drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, · line 1112
Quoted 13 lines
drivers/mmc/core/sd.c +3
-1mmc_remove_card (card); - + }return err; }@@ -1106,7 +1107,9 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,static void mmc_sd_remove (struct mmc_host *host) {mmc_remove_card (host->card); +mmc_claim_host (host); host->card =NULL ; +mmc_release_host (host);
Huh? What is this "fixing"?
Again, please break all of these out into logical bugfixes and describe what you are doing.
thanks,
greg k-h
Re: [<PATCH v1> 9/9] mmc: sd: Fix trivial SD card issues
Quoted 225 lines · Greg KH
Quoted 3 lines · Bao D. Nguyen
From: "Bao D. Nguyen" <[email protected]>
Fix various trivial SD card issues.
There are a number of real bugfixes in here, please split these out and put them at the beginning of the series so that they can be backported to the stable kernel tree. Specifics below:
Quoted 14 lines
Signed-off-by Bao D. Nguyen <[email protected]>--- drivers/mmc/core/block.c | 4 ++-- drivers/mmc/core/bus.c | 13 +++++++++++++ drivers/mmc/core/core.c | 13 ++++++++----- drivers/mmc/core/sd.c | 9 ++++++--- 4 files changed, 29 insertions(+), 10 deletions(-)drivers/mmc/core/block.c +0
-0drivers/mmc/core/block.c static int mmc_blk_ioctl_cmd(struct mmc_blk_data · line 657
Quoted 6 lines
drivers/mmc/core/block.c +1
-1@@ -653,13 +653,13 @@ static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md, struct request *req; idata =mmc_blk_ioctl_copy_from_user (ic_ptr); -if (IS_ERR (idata)) +if (IS_ERR_OR_NULL (idata))How can this function ever return NULL?
drivers/mmc/core/block.c static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md, · line 657
Quoted 1 line
drivers/mmc/core/block.c +0
-0return PTR_ERR (idata);If NULL was returned, are you sure you can return 0 here? That implies that all went well, when obviously it did not.
But again, I do not see how
mmc_blk_ioctl_copy_from_user()can return NULL, do you?drivers/mmc/core/block.c static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md, · line 662
Quoted 6 lines
drivers/mmc/core/block.c +1
-1/* This will be NULL on non-RPMB ioctl():s */ idata->rpmb = rpmb; card = md->queue.card; -if (IS_ERR (card)) { +if (IS_ERR_OR_NULL (card)) {How can card be NULL?
drivers/mmc/core/block.c static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md, · line 663
Quoted 1 line
drivers/mmc/core/block.c +0
-0err =PTR_ERR (card);Again, returning "success" is ok? Are you sure?
drivers/mmc/core/bus.c static void mmc_bus_shutdown(struct device *dev) · line 135
Quoted 12 lines
drivers/mmc/core/block.c +0
-0goto cmd_done;drivers/mmc/core/block.c +0
-0}drivers/mmc/core/bus.c +2
-0@@ -131,6 +131,16 @@ static void mmc_bus_shutdown(struct device *dev)struct mmc_host *host = card->host;int ret; +if (!drv) { +pr_debug ("%s: %s: drv is NULL\n" ,dev_name (dev), __func__);How can this ever happen?
And never use pr_* calls in a driver, you have a valid device, use
dev_dbg()and friends.drivers/mmc/core/bus.c static void mmc_bus_shutdown(struct device *dev) · line 140
Quoted 5 lines
drivers/mmc/core/bus.c +5
-0+return ; + } + +if (!card) { +pr_debug ("%s: %s: card is NULL\n" ,dev_name (dev), __func__);Same here, how can this ever happen?
Quoted 10 lines
drivers/mmc/core/bus.c +3
-0+return ; + } +if (dev->driver && drv->shutdown) drv->shutdown (card);@@ -247,12 +257,15 @@ void mmc_unregister_driver(struct mmc_driver *drv)static void mmc_release_card (struct device *dev) {drivers/mmc/core/bus.c void mmc_unregister_driver(struct mmc_driver · line 269
Quoted 10 lines
drivers/mmc/core/bus.c +3
-0struct mmc_card *card =mmc_dev_to_card (dev); +struct mmc_host *host = card->host;sdio_free_common_cis (card);kfree (card->info);kfree (card); +if (host) + host->card =NULL ;Why are you setting this to null? Does this solve some race condition that you are then catching in the shutdown callback? If so, this should be broken out as a separate bugfix and put earlier in the series as that should go to all stable kernels, right?
Quoted 8 lines
drivers/mmc/core/bus.c +0
-0}/*
drivers/mmc/core/core.c +0
-0drivers/mmc/core/core.c void mmc_wait_for_req_done(struct mmc_host *host, · line 403
Quoted 6 lines
drivers/mmc/core/core.c +1
-1@@ -399,7 +399,7 @@ void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq)struct mmc_command *cmd;while (1 ) { -wait_for_completion (&mrq->completion); +wait_for_completion_io (&mrq->completion);Why this change? That seems like a big one. Why is this not a separate patch?
drivers/mmc/core/core.c void mmc_set_data_timeout(struct mmc_data *data, · line 671
Quoted 10 lines
drivers/mmc/core/core.c +2
-0cmd = mrq->cmd;@@ -666,6 +666,10 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card) {unsigned int mult; +if (!card) { +WARN_ON (1 );And you just crashed systems that run with panic-on-warn :(
How can this ever happen? If it is a real issue, catch it, log it, and then move on, don't splat the kernel log with a full traceback and reboot machines :(
drivers/mmc/core/core.c void mmc_rescan(struct work_struct *work) · line 2348
Quoted 10 lines
drivers/mmc/core/core.c +2
-0+return ; + }/* * SDIO cards only define an upper 1 s limit on access. drivers/mmc/core/core.c +1
-0*/ @@ -2341,17 +2345,16 @@ void mmc_rescan(struct work_struct *work)void mmc_start_host (struct mmc_host *host) { +mmc_claim_host (host);What? This is a totally separate change, plaese break this out and describe what you are fixing here. Again, should be a bugfix for earlier in the series.
drivers/mmc/core/core.c void mmc_rescan(struct work_struct *work) · line 2357
Quoted 13 lines
drivers/mmc/core/core.c +2
-4host->f_init =max (freqs[0 ], host->f_min); host->rescan_disable =0 ; host->ios.power_mode =MMC_POWER_UNDEFINED ; -if (!(host->caps2 &MMC_CAP2_NO_PRESCAN_POWERUP )) { -mmc_claim_host (host); +if (!(host->caps2 &MMC_CAP2_NO_PRESCAN_POWERUP ))mmc_power_up (host, host->ocr_avail); -mmc_release_host (host); - }mmc_gpiod_request_cd_irq (host); +mmc_release_host (host);And are you sure the reference counting is correct here? Before this patch, you dropped the reference above, now you are matching it. Either this is wrong, or the original code is wrong. Either way, you need to describe it much better please.
drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host *host, · line 993
Quoted 13 lines
drivers/mmc/core/core.c +0
-0_mmc_detect_change (host,0 , false); }drivers/mmc/core/sd.c +1
-0@@ -989,6 +989,7 @@ static int mmc_sd_init_card(struct mmc_host *host,u32 ocr, err =mmc_send_relative_addr (host, &card->rca);if (err) goto free_card; + host->card = card;Why?
Quoted 5 lines
drivers/mmc/core/sd.c +0
-0}drivers/mmc/core/sd.c +0
-0if (!oldcard) {@@ -1090,13 +1091,13 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host · line 1099
Quoted 10 lines
drivers/mmc/core/sd.c +2
-2goto free_card; } done: - host->card = card;return 0 ; free_card: -if (!oldcard) +if (!oldcard) { + host->card =NULL ;Again, why?
Quoted 7 lines
drivers/mmc/core/sd.c +1
-1mmc_remove_card (card); - + }return err; }drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host · line 1113
Quoted 7 lines
drivers/mmc/core/sd.c +2
-0@@ -1106,7 +1107,9 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, static void mmc_sd_remove(struct mmc_host *host) {mmc_remove_card (host->card); +mmc_claim_host (host); host->card =NULL ; +mmc_release_host (host);Huh? What is this "fixing"?
Quoted 6 lines
Again, please break all of these out into logical bugfixes and describe what you are doing.
thanks,
greg k-h
Thank you for providing the feedback. There are a lot of good feedback and it will take me a bit of time to review them and make changes properly.
Regards,
Bao
Quoted 5 lines · Bao D. Nguyen
These patches include SD card genernal bug fixes.
Bao D. Nguyen (2):
mmc: core: Add a cap to use long discard size
mmc: sd: Fix trivial SD card issues
<snip>
Odd use of "<" and ">" in your subject lines, how did git create such a thing?
thanks,
greg k-h