linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: core: Add error check to avoid kernel panic caused by NULL pointer
@ 2020-06-02 17:29 Corey Gao
  2020-06-16 11:26 ` Ulf Hansson
  0 siblings, 1 reply; 2+ messages in thread
From: Corey Gao @ 2020-06-02 17:29 UTC (permalink / raw)
  To: ulf.hansson; +Cc: linux-mmc, linux-kernel, gaoce123

If __mmc_start_req(host, mrq) fails with error, the mrq->cmd->mrq will
be NULL. This will cause kernel panic in the following
mmc_wait_for_req_done(host, mrq). Add error check to cancle unnecessary
mmc_wait_for_req_done(host, mrq) if __mmc_start_req(host, mrq) fails.

Signed-off-by: Corey Gao <gaoce123@gmail.com>
---
 drivers/mmc/core/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 2553d903a82b..b13b484e64aa 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -734,9 +734,11 @@ EXPORT_SYMBOL(mmc_start_req);
  */
 void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
 {
-	__mmc_start_req(host, mrq);
+	int err;
 
-	if (!mrq->cap_cmd_during_tfr)
+	err = __mmc_start_req(host, mrq);
+
+	if (!mrq->cap_cmd_during_tfr && !err)
 		mmc_wait_for_req_done(host, mrq);
 }
 EXPORT_SYMBOL(mmc_wait_for_req);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mmc: core: Add error check to avoid kernel panic caused by NULL pointer
  2020-06-02 17:29 [PATCH] mmc: core: Add error check to avoid kernel panic caused by NULL pointer Corey Gao
@ 2020-06-16 11:26 ` Ulf Hansson
  0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2020-06-16 11:26 UTC (permalink / raw)
  To: Corey Gao; +Cc: linux-mmc, Linux Kernel Mailing List

On Tue, 2 Jun 2020 at 19:31, Corey Gao <gaoce123@gmail.com> wrote:
>
> If __mmc_start_req(host, mrq) fails with error, the mrq->cmd->mrq will
> be NULL. This will cause kernel panic in the following
> mmc_wait_for_req_done(host, mrq). Add error check to cancle unnecessary
> mmc_wait_for_req_done(host, mrq) if __mmc_start_req(host, mrq) fails.

The above is a bit hard for me to follow, can you please try to
elaborate on the problem. Moreover, please, provide a stack trace, as
that is easier to follow for me.

Kind regards
Uffe

>
> Signed-off-by: Corey Gao <gaoce123@gmail.com>
> ---
>  drivers/mmc/core/core.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 2553d903a82b..b13b484e64aa 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -734,9 +734,11 @@ EXPORT_SYMBOL(mmc_start_req);
>   */
>  void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
>  {
> -       __mmc_start_req(host, mrq);
> +       int err;
>
> -       if (!mrq->cap_cmd_during_tfr)
> +       err = __mmc_start_req(host, mrq);
> +
> +       if (!mrq->cap_cmd_during_tfr && !err)
>                 mmc_wait_for_req_done(host, mrq);
>  }
>  EXPORT_SYMBOL(mmc_wait_for_req);
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-16 11:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02 17:29 [PATCH] mmc: core: Add error check to avoid kernel panic caused by NULL pointer Corey Gao
2020-06-16 11:26 ` Ulf Hansson

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).