From patchwork Fri Jul 31 20:52:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Sierra X-Patchwork-Id: 6918371 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C3852C05AC for ; Fri, 31 Jul 2015 20:53:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CE65B20658 for ; Fri, 31 Jul 2015 20:53:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E130420656 for ; Fri, 31 Jul 2015 20:53:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753370AbbGaUxl (ORCPT ); Fri, 31 Jul 2015 16:53:41 -0400 Received: from xes-mad.com ([216.165.139.218]:38653 "EHLO xes-mad.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1945947AbbGaUx0 (ORCPT ); Fri, 31 Jul 2015 16:53:26 -0400 Received: from zimbra.xes-mad.com (zimbra.xes-mad.com [10.52.0.127]) by xes-mad.com (8.13.8/8.13.8) with ESMTP id t6VKqIMp007685; Fri, 31 Jul 2015 15:52:19 -0500 Date: Fri, 31 Jul 2015 15:52:18 -0500 (CDT) From: Aaron Sierra To: Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, Christophe Leroy Message-ID: <296998949.155413.1438375938630.JavaMail.zimbra@xes-inc.com> In-Reply-To: <985540634.83104.1438363661992.JavaMail.zimbra@xes-inc.com> Subject: [PATCH] crypto: talitos: Prevent panic in probe error path MIME-Version: 1.0 X-Originating-IP: [10.52.16.65] X-Mailer: Zimbra 8.0.6_GA_5922 (ZimbraWebClient - FF39 (Linux)/8.0.6_GA_5922) Thread-Topic: crypto: talitos: Prevent panic in probe error path Thread-Index: Zod1qD/6D0dGFf2+Kti7I3TiqUFZPg== Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 RNG unregistration and per-channel FIFO cleanup can cause a kernel panic, depending on how early in talitos_probe() an error occurs. This patch prevents these panics from happening. For completeness, this patch also sets device drvdata to NULL after the private structure is freed in talitos_remove(). Signed-off-by: Aaron Sierra --- drivers/crypto/talitos.c | 33 +++++++++++++++++++++++---------- drivers/crypto/talitos.h | 2 +- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 83aca95..684fe89 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -766,21 +766,33 @@ static int talitos_rng_init(struct hwrng *rng) static int talitos_register_rng(struct device *dev) { struct talitos_private *priv = dev_get_drvdata(dev); + int err = 0; - priv->rng.name = dev_driver_string(dev), - priv->rng.init = talitos_rng_init, - priv->rng.data_present = talitos_rng_data_present, - priv->rng.data_read = talitos_rng_data_read, - priv->rng.priv = (unsigned long)dev; + priv->rng = kzalloc(sizeof(struct hwrng), GFP_KERNEL); + if (!priv->rng) + return -ENOMEM; + + priv->rng->name = dev_driver_string(dev), + priv->rng->init = talitos_rng_init, + priv->rng->data_present = talitos_rng_data_present, + priv->rng->data_read = talitos_rng_data_read, + priv->rng->priv = (unsigned long)dev; + + err = hwrng_register(priv->rng); + if (err) { + kfree(priv->rng); + priv->rng = NULL; + } - return hwrng_register(&priv->rng); + return err; } static void talitos_unregister_rng(struct device *dev) { struct talitos_private *priv = dev_get_drvdata(dev); - hwrng_unregister(&priv->rng); + if (priv->rng) + hwrng_unregister(priv->rng); } /* @@ -2727,7 +2739,7 @@ static int talitos_remove(struct platform_device *ofdev) if (hw_supports(dev, DESC_HDR_SEL0_RNG)) talitos_unregister_rng(dev); - for (i = 0; i < priv->num_channels; i++) + for (i = 0; priv->chan && i < priv->num_channels; i++) kfree(priv->chan[i].fifo); kfree(priv->chan); @@ -2746,6 +2758,8 @@ static int talitos_remove(struct platform_device *ofdev) kfree(priv); + dev_set_drvdata(dev, NULL); + return 0; } @@ -2905,8 +2919,7 @@ static int talitos_probe(struct platform_device *ofdev) priv->reg = of_iomap(np, 0); if (!priv->reg) { dev_err(dev, "failed to of_iomap\n"); - err = -ENOMEM; - goto err_out; + return -ENOMEM; } /* get SEC version capabilities from device tree */ diff --git a/drivers/crypto/talitos.h b/drivers/crypto/talitos.h index bf88fe7..e86f67c 100644 --- a/drivers/crypto/talitos.h +++ b/drivers/crypto/talitos.h @@ -148,7 +148,7 @@ struct talitos_private { struct list_head alg_list; /* hwrng device */ - struct hwrng rng; + struct hwrng *rng; }; extern int talitos_submit(struct device *dev, int ch, struct talitos_desc *desc,