From patchwork Thu Dec 12 22:42:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King - ARM Linux X-Patchwork-Id: 3334881 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 24EE8C0D4A for ; Thu, 12 Dec 2013 22:43:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4F71E207F4 for ; Thu, 12 Dec 2013 22:43:51 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5A021207EF for ; Thu, 12 Dec 2013 22:43:50 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VrEyx-0000m6-52; Thu, 12 Dec 2013 22:43:47 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VrEyu-0004Sz-Ly; Thu, 12 Dec 2013 22:43:44 +0000 Received: from [2002:4e20:1eda::1] (helo=caramon.arm.linux.org.uk) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VrEyr-0004SK-KS for linux-arm-kernel@lists.infradead.org; Thu, 12 Dec 2013 22:43:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=caramon; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=EaDvjOIJxBL7rjzmj/gkmHz3bne0z0u5kewpJFdhmGw=; b=JkJVCyXJi+wy3UTTcDQiCJet6crXfRikGb5+BSy9aFSHuIWhqOUHe3iKokd8YjCCqTozPw7SLWi0tdgvGHznGTW1jFvt8rW4eaho//C7BoVnFYRS7QAsXxuTqo2ebHauwCMB3zhm2m5AvIn6D/K/PXrQNn6e2Ejs+rd/B3BfBmo=; Received: from n2100.arm.linux.org.uk ([2002:4e20:1eda:1:214:fdff:fe10:4f86]:52555) by caramon.arm.linux.org.uk with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1VrEy3-00013P-Al; Thu, 12 Dec 2013 22:42:51 +0000 Received: from linux by n2100.arm.linux.org.uk with local (Exim 4.76) (envelope-from ) id 1VrEy2-0004n0-1w; Thu, 12 Dec 2013 22:42:50 +0000 Date: Thu, 12 Dec 2013 22:42:49 +0000 From: Russell King - ARM Linux To: Aaro Koskinen Subject: Re: [PATCH] dma: mv_xor: fix kernel crash on probe error Message-ID: <20131212224249.GX4360@n2100.arm.linux.org.uk> References: <1386882715-16433-1-git-send-email-aaro.koskinen@iki.fi> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1386882715-16433-1-git-send-email-aaro.koskinen@iki.fi> User-Agent: Mutt/1.5.19 (2009-01-05) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131212_174342_052531_30C331C1 X-CRM114-Status: GOOD ( 17.67 ) X-Spam-Score: -1.0 (-) Cc: Vinod Koul , dmaengine@vger.kernel.org, Dan Williams , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Dec 12, 2013 at 11:11:55PM +0200, Aaro Koskinen wrote: > If the non-DT channel add path fails, the kernel will crash as the > channel is not set to NULL and it will try to release the channel using > the error value. Fix that. > > Signed-off-by: Aaro Koskinen > --- > drivers/dma/mv_xor.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c > index 7807f0ef4e20..2cb35a62c7f0 100644 > --- a/drivers/dma/mv_xor.c > +++ b/drivers/dma/mv_xor.c > @@ -1227,6 +1227,7 @@ static int mv_xor_probe(struct platform_device *pdev) > cd->cap_mask, irq); > if (IS_ERR(xordev->channels[i])) { > ret = PTR_ERR(xordev->channels[i]); > + xordev->channels[i] = NULL; > goto err_channel_add; > } > } Yes, I found this too, and although this is _a_ fix, it's not my preferred. I'd much prefer this instead - avoid writing invalid channels to xordev->channels[i] in the first place... Slightly larger patch but IMHO more correct. diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c index 7807f0ef4e20..a7e91090443e 100644 --- a/drivers/dma/mv_xor.c +++ b/drivers/dma/mv_xor.c @@ -1176,6 +1176,7 @@ static int mv_xor_probe(struct platform_device *pdev) int i = 0; for_each_child_of_node(pdev->dev.of_node, np) { + struct mv_xor_chan *chan; dma_cap_mask_t cap_mask; int irq; @@ -1193,21 +1194,21 @@ static int mv_xor_probe(struct platform_device *pdev) goto err_channel_add; } - xordev->channels[i] = - mv_xor_channel_add(xordev, pdev, i, - cap_mask, irq); - if (IS_ERR(xordev->channels[i])) { - ret = PTR_ERR(xordev->channels[i]); - xordev->channels[i] = NULL; + chan = mv_xor_channel_add(xordev, pdev, i, + cap_mask, irq); + if (IS_ERR(chan)) { + ret = PTR_ERR(chan); irq_dispose_mapping(irq); goto err_channel_add; } + xordev->channels[i] = chan; i++; } } else if (pdata && pdata->channels) { for (i = 0; i < MV_XOR_MAX_CHANNELS; i++) { struct mv_xor_channel_data *cd; + struct mv_xor_chan *chan; int irq; cd = &pdata->channels[i]; @@ -1222,13 +1223,14 @@ static int mv_xor_probe(struct platform_device *pdev) goto err_channel_add; } - xordev->channels[i] = - mv_xor_channel_add(xordev, pdev, i, - cd->cap_mask, irq); - if (IS_ERR(xordev->channels[i])) { - ret = PTR_ERR(xordev->channels[i]); + chan = mv_xor_channel_add(xordev, pdev, i, + cd->cap_mask, irq); + if (IS_ERR(chan)) { + ret = PTR_ERR(chan); goto err_channel_add; } + + xordev->channels[i] = chan; } }