Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965403AbeALVpH (ORCPT + 1 other); Fri, 12 Jan 2018 16:45:07 -0500 Received: from smtp09.smtpout.orange.fr ([80.12.242.131]:27324 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965253AbeALVo6 (ORCPT ); Fri, 12 Jan 2018 16:44:58 -0500 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Fri, 12 Jan 2018 22:44:57 +0100 X-ME-IP: 90.107.118.99 From: Christophe JAILLET To: balbi@kernel.org, gregkh@linuxfoundation.org, bhumirks@gmail.com, leoyang.li@nxp.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 3/4] usb: gadget: fotg210-udc: Simplify code Date: Fri, 12 Jan 2018 22:44:32 +0100 Message-Id: <5e33abfcfc7dc0c75fb5714b0cf5819cff72203d.1515791144.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.14.1 In-Reply-To: <0c3925c9ee4e56cd819347ab9ec515011b54d0ae.1515791144.git.christophe.jaillet@wanadoo.fr> References: <0c3925c9ee4e56cd819347ab9ec515011b54d0ae.1515791144.git.christophe.jaillet@wanadoo.fr> In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Use 'devm_kzalloc()' and 'devm_ioremap()' to simplify code. While at it, turn some '== NULL' into shorter '!' when testing memory allocation failure. Signed-off-by: Christophe JAILLET --- drivers/usb/gadget/udc/fotg210-udc.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c index a4d46b9759be..99a18b14c8c2 100644 --- a/drivers/usb/gadget/udc/fotg210-udc.c +++ b/drivers/usb/gadget/udc/fotg210-udc.c @@ -1065,11 +1065,8 @@ static int fotg210_udc_remove(struct platform_device *pdev) struct fotg210_udc *fotg210 = platform_get_drvdata(pdev); usb_del_gadget_udc(&fotg210->gadget); - iounmap(fotg210->reg); free_irq(platform_get_irq(pdev, 0), fotg210); - fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req); - kfree(fotg210); return 0; } @@ -1096,21 +1093,22 @@ static int fotg210_udc_probe(struct platform_device *pdev) ret = -ENOMEM; /* initialize udc */ - fotg210 = kzalloc(sizeof(struct fotg210_udc), GFP_KERNEL); - if (fotg210 == NULL) - goto err_alloc; + fotg210 = devm_kzalloc(&pdev->dev, sizeof(struct fotg210_udc), + GFP_KERNEL); + if (!fotg210) + return -ENOMEM; for (i = 0; i < FOTG210_MAX_NUM_EP; i++) { fotg210->ep[i] = devm_kzalloc(&pdev->dev, sizeof(struct fotg210_ep), GFP_KERNEL); if (!fotg210->ep[i]) - goto err_alloc; + return -ENOMEM; } - fotg210->reg = ioremap(res->start, resource_size(res)); - if (fotg210->reg == NULL) { + fotg210->reg = devm_ioremap(&pdev->dev, res->start, resource_size(res)); + if (!fotg210->reg) { pr_err("ioremap error.\n"); - goto err_map; + return -ENOMEM; } spin_lock_init(&fotg210->lock); @@ -1185,13 +1183,6 @@ static int fotg210_udc_probe(struct platform_device *pdev) err_req: fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req); -err_map: - if (fotg210->reg) - iounmap(fotg210->reg); - -err_alloc: - kfree(fotg210); - return ret; } -- 2.14.1