From patchwork Tue Oct 18 08:43:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 9381635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 93D4B607D0 for ; Tue, 18 Oct 2016 08:43:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8211B28DC3 for ; Tue, 18 Oct 2016 08:43:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 768ED29348; Tue, 18 Oct 2016 08:43:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E97DA28DC3 for ; Tue, 18 Oct 2016 08:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754599AbcJRInx (ORCPT ); Tue, 18 Oct 2016 04:43:53 -0400 Received: from up.free-electrons.com ([163.172.77.33]:53035 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752327AbcJRInv (ORCPT ); Tue, 18 Oct 2016 04:43:51 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 16E54221E9; Tue, 18 Oct 2016 10:43:45 +0200 (CEST) Received: from localhost (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id DF2D72200E; Tue, 18 Oct 2016 10:43:44 +0200 (CEST) From: Maxime Ripard To: Ulf Hansson Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, Maxime Ripard Subject: [PATCH] mmc: core: Check regulator pointer Date: Tue, 18 Oct 2016 10:43:43 +0200 Message-Id: <20161018084343.680-1-maxime.ripard@free-electrons.com> X-Mailer: git-send-email 2.9.3 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP mmc_regulator_get_supply might silently fail if the regulators are not found, which is the right thing to do since both these regulators are optional. However, the drivers then have no way to know whether or not they should proceed and call mmc_regulator_set_ocr. And since this function doesn't check for the validity of the regulator pointer, it leads to a null pointer dereference. Add such a check to make sure everything works fine. Signed-off-by: Maxime Ripard --- drivers/mmc/core/core.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 2553d903a82b..1d3ea5e1aa37 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1474,6 +1474,12 @@ int mmc_regulator_set_ocr(struct mmc_host *mmc, int result = 0; int min_uV, max_uV; + if (!supply) + return -EINVAL; + + if (IS_ERR(supply)) + return PTR_ERR(supply); + if (vdd_bit) { mmc_ocrbitnum_to_vdd(vdd_bit, &min_uV, &max_uV);