From patchwork Tue Jun 18 12:05:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 167148 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4128510ilk; Tue, 18 Jun 2019 05:05:23 -0700 (PDT) X-Received: by 2002:a19:ca0e:: with SMTP id a14mr2774997lfg.19.1560859523380; Tue, 18 Jun 2019 05:05:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560859523; cv=none; d=google.com; s=arc-20160816; b=BnjiuCQoUOiW4Ffh5cRAIjGDqCiAio2wUXE1Y+dsNg50nxHHONw2GyCgwlQLfFq1zb HccdPPohwBiREF/NvVIX4/SZeLaf0nJT/7mugdntygKejZRNevCdqHVCvQUshfD3Ahah VYvhu2JM0O7Am7Q05EB1YvLh0UlWiq7097ib1TiQTi0zMV/+CFXCI8Tujp36dfhJXivD FBZLgldklxmKGnSHS/Hp4r4y5dMbj8/d0pRu9o98WAxKPU2PfmxsvRmfa1P+Iw724a4C zzUT0XDT7stOT+NPIi+smV5X9hIhncTqobJ8f/EuO52jzpqa4gkUrbvqQ4e/pGdI7gny d1iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=Bg8QqDQoZIq/5wmDEJaOxBNPAWkAsd1tFZ5D6LNidQw=; b=RvBNxtAxO/cWsi+dqe1hN/q0w4+URy25O6O3LhWb8qPgJrlAvyGqS2g7bkfcrxHCzu ts19XqQWqW2T367/uYxnBGYwmRTnrENfvBUpoJuARqwLg+rWTH1g6AAMcGR2E6RQUIZJ U8VFzrpIIKKf7pH6lRds3MpN6aGm32hXc+vMvuHHt1Qrt+ArqrlWdaLzVTNAxOgv9z8s JCnSjpivoqN0sIEG4vHr9TSQL/ufzA9hPgjLQha9OFiXzeDswkJJsBathnKJ4sVgFmz4 kIyHYYh6typsCwCAZ254NXkLTIvg1TWCxYW+iBYS7bSqN+zwEcn6DEo/ncvCszt+Ztjd TVFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qr2S0sjS; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m90sor7919025lje.28.2019.06.18.05.05.23 for (Google Transport Security); Tue, 18 Jun 2019 05:05:23 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qr2S0sjS; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=Bg8QqDQoZIq/5wmDEJaOxBNPAWkAsd1tFZ5D6LNidQw=; b=qr2S0sjS3RepdjF6+LNucEQ3iBw2UY5MT5ExudDZ46nwwFLC/H/Ii11UDx/nXGoNrn VDJI+lrkLjfWCL57AXv11MyrxiyACQIpA6S7tzjDBHIYowtcxwbdv7J+QTMVGOf8ey8B HGI9JoMqtX4x9kGSEVTSfdqlw6gnM01bhfCzO4lXAu+Mh8tdr78T0S5ZX4uvYZG/8UNT t8JJZbXDtpULS5us5eyZ031XoqIdxi6oj0ZTtZL3CVWon2e6x+mYj2hTUTVGoQ8KDrIV wDjIlAm9KycrMKXdeF+gMkbScOg4LHoSwlrH3wXuFX0+PEdAXp/UTbKRuLe8CYcdCtTa qspQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Bg8QqDQoZIq/5wmDEJaOxBNPAWkAsd1tFZ5D6LNidQw=; b=iMzKyynsjrE9lpwl88jVS+SFQTc/W2Ab0SNz4m6+MRpyI3oCAHK0orKSiiUXf0FTVu MQQhgxwdJH31lGMafksZgI/kiTfv+B0YXkAfbHgmyEtFtvBZTRWobOf9XZSPCpBgv2Un X5+cULMQGrvbQBaRaG0eDJSvyqpwtkjZo6ZOol16n4qLoIpu3MiM1KnfpjMG96wq+0Zn XNJnfqzooXbjmqQvioNsbG5PevusMNxNjjNTJkj71snHzi0qdPBirzqqj383j/yMzEj/ qnlblT0mXzSeCDvn0P1oF38xwh00CXC4xMGG+9E1gK4wwChB9bB2IQYHoFvlkRrjYGZy lABg== X-Gm-Message-State: APjAAAUYF9i2DE6ibtszsSGEUnOx/Ztj6wlrcYvrLK/7HWWQgwFaf1W6 EPW9hw/T7sF/bLRIe867M3DzoEF/ X-Google-Smtp-Source: APXvYqwAJpLDxl74LqLKNXFGb626+sV0+gyjztdfmoze+z1tsfu4A8ry8bv7JaM4GJBlfeJLDKfMDQ== X-Received: by 2002:a2e:8945:: with SMTP id b5mr22437486ljk.93.1560859522947; Tue, 18 Jun 2019 05:05:22 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id r11sm2849691ljh.90.2019.06.18.05.05.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jun 2019 05:05:21 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Douglas Anderson Cc: Adrian Hunter , Brian Norris , Shawn Lin , Guenter Roeck , Heiko Stuebner , Kalle Valo , linux-wireless@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2] mmc: core: Prevent processing SDIO IRQs when the card is suspended Date: Tue, 18 Jun 2019 14:05:17 +0200 Message-Id: <20190618120517.23123-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 Processing of SDIO IRQs must obviously be prevented while the card is system suspended, otherwise we may end up trying to communicate with an uninitialized SDIO card. Reports throughout the years shows that this is not only a theoretical problem, but a real issue. So, let's finally fix this problem, by keeping track of the state for the card and bail out before processing the SDIO IRQ, in case the card is suspended. Cc: stable@vger.kernel.org Reported-by: Douglas Anderson Tested-by: Douglas Anderson Signed-off-by: Ulf Hansson --- Changes in v2: - Respect error code in mmc_sdio_suspend(), pointed out by Doug. --- drivers/mmc/core/sdio.c | 13 ++++++++++++- drivers/mmc/core/sdio_irq.c | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index d1aa1c7577bb..712a7742765e 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -937,6 +937,10 @@ static int mmc_sdio_pre_suspend(struct mmc_host *host) */ static int mmc_sdio_suspend(struct mmc_host *host) { + /* Prevent processing of SDIO IRQs in suspended state. */ + mmc_card_set_suspended(host->card); + cancel_delayed_work_sync(&host->sdio_irq_work); + mmc_claim_host(host); if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) @@ -985,13 +989,20 @@ static int mmc_sdio_resume(struct mmc_host *host) err = sdio_enable_4bit_bus(host->card); } - if (!err && host->sdio_irqs) { + if (err) + goto out; + + /* Allow SDIO IRQs to be processed again. */ + mmc_card_clr_suspended(host->card); + + if (host->sdio_irqs) { if (!(host->caps2 & MMC_CAP2_SDIO_IRQ_NOTHREAD)) wake_up_process(host->sdio_irq_thread); else if (host->caps & MMC_CAP_SDIO_IRQ) host->ops->enable_sdio_irq(host, 1); } +out: mmc_release_host(host); host->pm_flags &= ~MMC_PM_KEEP_POWER; diff --git a/drivers/mmc/core/sdio_irq.c b/drivers/mmc/core/sdio_irq.c index 931e6226c0b3..9f54a259a1b3 100644 --- a/drivers/mmc/core/sdio_irq.c +++ b/drivers/mmc/core/sdio_irq.c @@ -34,6 +34,10 @@ static int process_sdio_pending_irqs(struct mmc_host *host) unsigned char pending; struct sdio_func *func; + /* Don't process SDIO IRQs if the card is suspended. */ + if (mmc_card_suspended(card)) + return 0; + /* * Optimization, if there is only 1 function interrupt registered * and we know an IRQ was signaled then call irq handler directly.