From patchwork Wed Aug 29 18:08:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timur Tabi X-Patchwork-Id: 180744 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 0A2172C0169 for ; Thu, 30 Aug 2012 04:08:45 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754477Ab2H2SIk (ORCPT ); Wed, 29 Aug 2012 14:08:40 -0400 Received: from co1ehsobe001.messaging.microsoft.com ([216.32.180.184]:31126 "EHLO co1outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754468Ab2H2SIj (ORCPT ); Wed, 29 Aug 2012 14:08:39 -0400 Received: from mail105-co1-R.bigfish.com (10.243.78.245) by CO1EHSOBE010.bigfish.com (10.243.66.73) with Microsoft SMTP Server id 14.1.225.23; Wed, 29 Aug 2012 18:08:39 +0000 Received: from mail105-co1 (localhost [127.0.0.1]) by mail105-co1-R.bigfish.com (Postfix) with ESMTP id 1AC06380120; Wed, 29 Aug 2012 18:08:39 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bhz2dh2a8h668h839hd24he5bhf0ah107ah1155h) Received: from mail105-co1 (localhost.localdomain [127.0.0.1]) by mail105-co1 (MessageSwitch) id 1346263701249274_2803; Wed, 29 Aug 2012 18:08:21 +0000 (UTC) Received: from CO1EHSMHS020.bigfish.com (unknown [10.243.78.244]) by mail105-co1.bigfish.com (Postfix) with ESMTP id 7CF6390005E; Wed, 29 Aug 2012 18:08:10 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO1EHSMHS020.bigfish.com (10.243.66.30) with Microsoft SMTP Server (TLS) id 14.1.225.23; Wed, 29 Aug 2012 18:08:09 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-003.039d.mgd.msft.net (10.84.1.16) with Microsoft SMTP Server (TLS) id 14.2.309.3; Wed, 29 Aug 2012 13:08:07 -0500 Received: from efes.am.freescale.net (efes.am.freescale.net [10.82.123.3]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id q7TI84DW015080; Wed, 29 Aug 2012 11:08:07 -0700 From: Timur Tabi To: Andy Fleming , David Miller , Subject: [PATCH 6/7] net/fsl-pq-mdio: coalesce multiple memory allocations into one Date: Wed, 29 Aug 2012 13:08:02 -0500 Message-ID: <1346263683-3664-6-git-send-email-timur@freescale.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1346263683-3664-1-git-send-email-timur@freescale.com> References: <1346263683-3664-1-git-send-email-timur@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Take advantage of the new mdiobus_alloc_size() function to combine three different memory allocations into one. This also simplies the error handling. Signed-off-by: Timur Tabi --- drivers/net/ethernet/freescale/fsl_pq_mdio.c | 42 ++++++++----------------- 1 files changed, 14 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/freescale/fsl_pq_mdio.c b/drivers/net/ethernet/freescale/fsl_pq_mdio.c index 7eef1bb..ebd4638 100644 --- a/drivers/net/ethernet/freescale/fsl_pq_mdio.c +++ b/drivers/net/ethernet/freescale/fsl_pq_mdio.c @@ -68,6 +68,7 @@ struct fsl_pq_mdio { struct fsl_pq_mdio_priv { void __iomem *map; struct fsl_pq_mii __iomem *regs; + int irqs[PHY_MAX_ADDR]; }; /* @@ -359,26 +360,21 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "found %s compatible node\n", id->compatible); - priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) + new_bus = mdiobus_alloc_size(sizeof(*priv)); + if (!new_bus) return -ENOMEM; - new_bus = mdiobus_alloc(); - if (!new_bus) { - err = -ENOMEM; - goto err_free_priv; - } - + priv = new_bus->priv; new_bus->name = "Freescale PowerQUICC MII Bus", new_bus->read = &fsl_pq_mdio_read; new_bus->write = &fsl_pq_mdio_write; new_bus->reset = &fsl_pq_mdio_reset; - new_bus->priv = priv; + new_bus->irq = priv->irqs; err = of_address_to_resource(np, 0, &res); if (err < 0) { dev_err(&pdev->dev, "could not obtain address information\n"); - goto err_free_bus; + goto error; } snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s@%llx", np->name, @@ -387,7 +383,7 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev) priv->map = of_iomap(np, 0); if (!priv->map) { err = -ENOMEM; - goto err_free_bus; + goto error; } /* @@ -399,16 +395,10 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev) if (data->mii_offset > resource_size(&res)) { dev_err(&pdev->dev, "invalid register map\n"); err = -EINVAL; - goto err_unmap_regs; + goto error; } priv->regs = priv->map + data->mii_offset; - new_bus->irq = kcalloc(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL); - if (NULL == new_bus->irq) { - err = -ENOMEM; - goto err_unmap_regs; - } - new_bus->parent = &pdev->dev; dev_set_drvdata(&pdev->dev, new_bus); @@ -446,19 +436,17 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev) if (err) { dev_err(&pdev->dev, "cannot register %s as MDIO bus\n", new_bus->name); - goto err_free_irqs; + goto error; } return 0; -err_free_irqs: - kfree(new_bus->irq); -err_unmap_regs: - iounmap(priv->map); -err_free_bus: +error: + if (priv->map) + iounmap(priv->map); + kfree(new_bus); -err_free_priv: - kfree(priv); + return err; } @@ -474,9 +462,7 @@ static int fsl_pq_mdio_remove(struct platform_device *pdev) dev_set_drvdata(device, NULL); iounmap(priv->map); - bus->priv = NULL; mdiobus_free(bus); - kfree(priv); return 0; }