From patchwork Thu Mar 19 09:22:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 46018 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A1B2021515 for ; Thu, 19 Mar 2015 09:23:14 +0000 (UTC) Received: by wivz2 with SMTP id z2sf11810110wiv.1 for ; Thu, 19 Mar 2015 02:23:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=YiEG0tf+LUDYD1urSt8+Tnt3pHaOSkaxX1pfLbB4oys=; b=IqtwjoEyMiowFWonnPTxQumtvG31QvD0N694poLXmLl+NmrQvRuXVG7ul7YVXdd32Q SqFw4Su4lDzqt5YDvd5ViSkpgQAJN47MQU8fHdm3O/6rR2MIOmB4fb8/FJ9ztMGgixlA yB2nydcuKbo5qA+dio8bS9O3/q1EJMUoAlsARJvvF5uSrtqS4N8tJxaFXJ+LHeC7Fgxm SkRG5efgHdaCgkNOjgGCrGR/JaxAR2hxqtX31/86qbU5zDaezWgSPLqWdT7Arh3DQke/ VFSEdRe4mEJos3zgAhGNMviR2wqNGamGgcsSEWI+g8aF6t1gleaOjM1szwVNXZZrGH/0 lFpw== X-Gm-Message-State: ALoCoQlQB7jmAFb3Y6tti2yBOJkSUM1vbMQVtupfmG+aBixTA1hGzDuJe3ArUBfMULWgP/n5WfS6 X-Received: by 10.194.161.194 with SMTP id xu2mr11878870wjb.1.1426756993965; Thu, 19 Mar 2015 02:23:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.6.33 with SMTP id cr1ls225698lad.47.gmail; Thu, 19 Mar 2015 02:23:13 -0700 (PDT) X-Received: by 10.152.36.138 with SMTP id q10mr67083182laj.113.1426756993564; Thu, 19 Mar 2015 02:23:13 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id xk4si550287lac.75.2015.03.19.02.23.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 02:23:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by ladw1 with SMTP id w1so57009747lad.0 for ; Thu, 19 Mar 2015 02:23:13 -0700 (PDT) X-Received: by 10.112.160.65 with SMTP id xi1mr5216693lbb.56.1426756993312; Thu, 19 Mar 2015 02:23:13 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp257828lbj; Thu, 19 Mar 2015 02:23:12 -0700 (PDT) X-Received: by 10.70.90.233 with SMTP id bz9mr92557193pdb.47.1426756991408; Thu, 19 Mar 2015 02:23:11 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qa7si1895821pac.22.2015.03.19.02.23.10; Thu, 19 Mar 2015 02:23:11 -0700 (PDT) Received-SPF: none (google.com: linux-mmc-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750799AbbCSJXJ (ORCPT + 3 others); Thu, 19 Mar 2015 05:23:09 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:38248 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752261AbbCSJW5 (ORCPT ); Thu, 19 Mar 2015 05:22:57 -0400 Received: by wifj2 with SMTP id j2so63168382wif.1 for ; Thu, 19 Mar 2015 02:22:56 -0700 (PDT) X-Received: by 10.194.75.193 with SMTP id e1mr146165887wjw.126.1426756976354; Thu, 19 Mar 2015 02:22:56 -0700 (PDT) Received: from srini-ThinkPad-X1-Carbon-2nd.dlink.com (host-2-99-228-8.as13285.net. [2.99.228.8]) by mx.google.com with ESMTPSA id nd15sm1647545wic.8.2015.03.19.02.22.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2015 02:22:55 -0700 (PDT) From: Srinivas Kandagatla To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Chris Ball , linux-kernel@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH] mmc: pwrseq: fix logic in error handling. Date: Thu, 19 Mar 2015 09:22:13 +0000 Message-Id: <1426756933-19290-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-mmc-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: srinivas.kandagatla@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This bug was noticed by accident when I build kernel without a gpio driver resulting in exercising the error path. In the error handing path the index could go below zero resulting in infinite loop. This patch adds a check to fix the issue. Without this patch I hit the below kernel crash or kernel hang: Unable to handle kernel NULL pointer dereference at virtual address 00000002 pgd = c0204000 [00000002] *pgd=00000000 Internal error: Oops: 5 [#1] SMP ARM Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.0.0-rc4-00100-gda80c89-dirty #3 Hardware name: Qualcomm (Flattened Device Tree) task: ed858000 ti: ed842000 task.ti: ed842000 PC is at gpiod_unexport+0x14/0xc8 LR is at gpiod_unexport+0x14/0xc8 pc : [] lr : [] psr: 60000113 sp : ed843db0 ip : 00000000 fp : 00000000 r10: ed927c00 r9 : fffffdfb r8 : ed9a8e80 r7 : ed958610 r6 : 00000002 r5 : fffffffe r4 : fffffffe r3 : ed858000 r2 : ed843da8 r1 : 60000113 r0 : c0ea6ac8 Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kernel Control: 10c5787d Table: 8020406a DAC: 00000015 Process swapper/0 (pid: 1, stack limit = 0xed842220) Stack: (0xed843db0 to 0xed844000) 3da0: fffffffe fffffffe 00000002 c04ba420 3dc0: fffffffe fffffffe 00000002 ed958610 ed9a8e80 c04bb29c ed9a8e88 c07ec514 3de0: ed927c00 00000000 c0ee58a4 ed958600 ed9a8e10 00000000 c0ee5c28 c07ec1dc 3e00: 00000001 ed927c00 ee7edeb0 00000000 00000000 c07e2e94 00000000 ed843e27 3e20: 00000000 00007200 00000004 00000000 ed927c00 ed957200 ee7edeb0 c07f1868 3e40: ee7edeb0 c082eb70 ed858000 00000000 60000113 ed957200 fffffffe c0ee5a50 3e60: ed957200 c0ee5944 00000000 ed9572c4 c0de5564 00000000 00000000 c050d67c 3e80: ed957200 c0f6d59c 00000000 c0ee5944 00000000 c05eacf4 ed957200 c0ee5944 3ea0: ed957234 00000000 c0daed5c c05eaea0 00000000 c0ee5944 c05eae14 c05e9524 3ec0: ed82b95c ed9438b4 c0ee5944 edd3b700 c0ea9d74 c05ea4f4 c0ca8dd4 c0e29710 3ee0: c0ee5944 c0ee5944 c0e33818 edd3d200 c0f2f180 c05eb4e8 00000000 c0e33818 3f00: c0e33818 c0209a44 0000006a 00000000 c0c93134 c0d1c21c 00000000 ed843f30 3f20: c02622d0 c046c260 20000013 ffffffff ef7fcc75 c09d0408 00000118 c02624d0 3f40: c0d1bb7c 00000006 ef7fcc8d 00000006 c0e6d70c ef7fcbc0 c0e29710 00000006 3f60: c0de5558 c0f2f180 00000118 c0de5564 c0d65598 c0d65d6c 00000006 00000006 3f80: c0d65598 c09a5154 00000000 c09a5154 00000000 00000000 00000000 00000000 3fa0: 00000000 c09a515c 00000000 c020f6c0 00000000 00000000 00000000 00000000 3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 3fe0: 00000000 00000000 00000000 00000000 00000013 00000000 e5fdff45 9929cfe7 [] (gpiod_unexport) from [] (__gpiod_free+0xc/0xe0) [] (__gpiod_free) from [] (gpiod_free+0x10/0x28) [] (gpiod_free) from [] (mmc_pwrseq_simple_alloc+0xe0/0x128) [] (mmc_pwrseq_simple_alloc) from [] (mmc_pwrseq_alloc+0x90/0xb8) [] (mmc_pwrseq_alloc) from [] (mmc_of_parse+0x3b0/0x4f0) [] (mmc_of_parse) from [] (mmci_probe+0x50/0x828) [] (mmci_probe) from [] (amba_probe+0xcc/0x148) [] (amba_probe) from [] (driver_probe_device+0x10c/0x22c) [] (driver_probe_device) from [] (__driver_attach+0x8c/0x90) [] (__driver_attach) from [] (bus_for_each_dev+0x54/0x88) [] (bus_for_each_dev) from [] (bus_add_driver+0xd4/0x1d0) [] (bus_add_driver) from [] (driver_register+0x78/0xf4) [] (driver_register) from [] (do_one_initcall+0x80/0x1d0) [] (do_one_initcall) from [] (kernel_init_freeable+0x10c/0x1d8) [] (kernel_init_freeable) from [] (kernel_init+0x8/0xec) [] (kernel_init) from [] (ret_from_fork+0x14/0x34) Code: e2504000 0a000025 e59f00a0 eb13c440 (e5943004) ---[ end trace 80b84017d7c9e7e5 ]--- Signed-off-by: Srinivas Kandagatla --- drivers/mmc/core/pwrseq_simple.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/core/pwrseq_simple.c b/drivers/mmc/core/pwrseq_simple.c index e9f1d8d..6f0a875 100644 --- a/drivers/mmc/core/pwrseq_simple.c +++ b/drivers/mmc/core/pwrseq_simple.c @@ -124,8 +124,8 @@ int mmc_pwrseq_simple_alloc(struct mmc_host *host, struct device *dev) PTR_ERR(pwrseq->reset_gpios[i]) != -ENOSYS) { ret = PTR_ERR(pwrseq->reset_gpios[i]); - while (--i) - gpiod_put(pwrseq->reset_gpios[i]); + while (i > 0) + gpiod_put(pwrseq->reset_gpios[--i]); goto clk_put; }