From patchwork Fri Jan 15 20:33:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Timo_Ter=C3=A4s?= X-Patchwork-Id: 8044521 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AE3F59F88A for ; Fri, 15 Jan 2016 20:34:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B874C20390 for ; Fri, 15 Jan 2016 20:34:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 363D020381 for ; Fri, 15 Jan 2016 20:33:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753630AbcAOUd6 (ORCPT ); Fri, 15 Jan 2016 15:33:58 -0500 Received: from mail-lb0-f194.google.com ([209.85.217.194]:33782 "EHLO mail-lb0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752918AbcAOUd5 (ORCPT ); Fri, 15 Jan 2016 15:33:57 -0500 Received: by mail-lb0-f194.google.com with SMTP id bc4so21890300lbc.0 for ; Fri, 15 Jan 2016 12:33:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=tlYmA/u91cr8KRlnsVcidzM16ix3UasMk2KHLYu+bxM=; b=UibFx89NhU/CQWZ2TVF68Vz0PwR5184eAgA0XDwUzYE/zyZfHIdl/MHCMCIFN+vm3h bNn2NFs/OG1HOaOYiwEdZGJevLd9UYkJKxdTP5l58gx48+Tj71j/SRz87oPdgNsyaARc uKo8jC83C7efOOVxNSlBpJjdqZ/g+rluDAB3UbAKMXapERSQleN/0AvNxWkF8e3Kdr5y VBPEVxvJ908vZKO36rh+4rHK2rzb9ahCDfOCzeLxgDlPs3MhJR8oHqguRtfCrYR5W7bp jVYShfsMQWyZhFMD5vIit0yAa3FUr0cwJdaSUM2HfC02KLjejioF9DBSsJAddHWagJ/v 2E5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-type:content-transfer-encoding; bh=tlYmA/u91cr8KRlnsVcidzM16ix3UasMk2KHLYu+bxM=; b=XJAyURlwlNy1R8xHL+yZd4sti1HHpzvDit44FbIQw8QbU9SxfbaVkw14kCVCMfOTPA YBjBRPZ4/BWNOoGd4bDZj9/99E3j6Evq3rgq6lA4OTQ9/Q3yesXLzb9bEkkHt05iot9P dJokfk4XmXkjbHIsoKMo6xrsJsN370MZSaec0TsxpGTTI1C5lRzzKOhnWoHdbXO1z7PB Jq2RjID47fmWZJdKUNoo2B1EIXQLcoUSMJgm8D5AhG1sLUjh5aMROhPFbaV42H9ePqvJ 7mCGOHIrkIxASXqUeQPdJi0rsDPz339pwrESTWE2UB2z8w0Eh0wrTch87lrflEURfUTC Z7WA== X-Gm-Message-State: ALoCoQkhuKNVr7X3ep+q57X/rzXGVPxDYxldhLXtbJrrDdgA47zdIbLfBgcN0hlHirZke0yUeQe4dwMdNYs5tkqwXqI2xCHhxg== X-Received: by 10.112.13.8 with SMTP id d8mr3966212lbc.110.1452890035344; Fri, 15 Jan 2016 12:33:55 -0800 (PST) Received: from vostro.util.wtbts.net ([2001:1bc8:101:f402:21a:9fff:fe0c:4022]) by smtp.gmail.com with ESMTPSA id r200sm1593067lfd.35.2016.01.15.12.33.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Jan 2016 12:33:54 -0800 (PST) From: =?UTF-8?q?Timo=20Ter=C3=A4s?= To: "linux-input@vger.kernel.org" Cc: =?UTF-8?q?Timo=20Ter=C3=A4s?= Subject: [PATCH 1/3] Input: rotary_encoder - convert to devm-* api Date: Fri, 15 Jan 2016 22:33:48 +0200 Message-Id: <1452890030-23316-1-git-send-email-timo.teras@iki.fi> X-Mailer: git-send-email 2.7.0 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 Use managed resource API for simplifying error paths. Signed-off-by: Timo Teräs --- drivers/input/misc/rotary_encoder.c | 73 ++++++++++--------------------------- 1 file changed, 20 insertions(+), 53 deletions(-) diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index 8aee719..0f23d32 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c @@ -211,8 +211,8 @@ static struct rotary_encoder_platform_data *rotary_encoder_parse_dt(struct devic if (!of_id || !np) return NULL; - pdata = kzalloc(sizeof(struct rotary_encoder_platform_data), - GFP_KERNEL); + pdata = devm_kzalloc(dev, sizeof(struct rotary_encoder_platform_data), + GFP_KERNEL); if (!pdata) return ERR_PTR(-ENOMEM); @@ -277,12 +277,10 @@ static int rotary_encoder_probe(struct platform_device *pdev) } } - encoder = kzalloc(sizeof(struct rotary_encoder), GFP_KERNEL); - input = input_allocate_device(); - if (!encoder || !input) { - err = -ENOMEM; - goto exit_free_mem; - } + encoder = devm_kzalloc(dev, sizeof(struct rotary_encoder), GFP_KERNEL); + input = devm_input_allocate_device(dev); + if (!encoder || !input) + return -ENOMEM; encoder->input = input; encoder->pdata = pdata; @@ -301,16 +299,16 @@ static int rotary_encoder_probe(struct platform_device *pdev) } /* request the GPIOs */ - err = gpio_request_one(pdata->gpio_a, GPIOF_IN, dev_name(dev)); + err = devm_gpio_request_one(dev, pdata->gpio_a, GPIOF_IN, dev_name(dev)); if (err) { dev_err(dev, "unable to request GPIO %d\n", pdata->gpio_a); - goto exit_free_mem; + return err; } - err = gpio_request_one(pdata->gpio_b, GPIOF_IN, dev_name(dev)); + err = devm_gpio_request_one(dev, pdata->gpio_b, GPIOF_IN, dev_name(dev)); if (err) { dev_err(dev, "unable to request GPIO %d\n", pdata->gpio_b); - goto exit_free_gpio_a; + return err; } encoder->irq_a = gpio_to_irq(pdata->gpio_a); @@ -331,30 +329,29 @@ static int rotary_encoder_probe(struct platform_device *pdev) default: dev_err(dev, "'%d' is not a valid steps-per-period value\n", pdata->steps_per_period); - err = -EINVAL; - goto exit_free_gpio_b; + return-EINVAL; } - err = request_irq(encoder->irq_a, handler, - IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, - DRV_NAME, encoder); + err = devm_request_irq(dev, encoder->irq_a, handler, + IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, + DRV_NAME, encoder); if (err) { dev_err(dev, "unable to request IRQ %d\n", encoder->irq_a); - goto exit_free_gpio_b; + return err; } - err = request_irq(encoder->irq_b, handler, - IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, - DRV_NAME, encoder); + err = devm_request_irq(dev, encoder->irq_b, handler, + IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, + DRV_NAME, encoder); if (err) { dev_err(dev, "unable to request IRQ %d\n", encoder->irq_b); - goto exit_free_irq_a; + return err; } err = input_register_device(input); if (err) { dev_err(dev, "failed to register input device\n"); - goto exit_free_irq_b; + return err; } device_init_wakeup(&pdev->dev, pdata->wakeup_source); @@ -362,42 +359,12 @@ static int rotary_encoder_probe(struct platform_device *pdev) platform_set_drvdata(pdev, encoder); return 0; - -exit_free_irq_b: - free_irq(encoder->irq_b, encoder); -exit_free_irq_a: - free_irq(encoder->irq_a, encoder); -exit_free_gpio_b: - gpio_free(pdata->gpio_b); -exit_free_gpio_a: - gpio_free(pdata->gpio_a); -exit_free_mem: - input_free_device(input); - kfree(encoder); - if (!dev_get_platdata(&pdev->dev)) - kfree(pdata); - - return err; } static int rotary_encoder_remove(struct platform_device *pdev) { - struct rotary_encoder *encoder = platform_get_drvdata(pdev); - const struct rotary_encoder_platform_data *pdata = encoder->pdata; - device_init_wakeup(&pdev->dev, false); - free_irq(encoder->irq_a, encoder); - free_irq(encoder->irq_b, encoder); - gpio_free(pdata->gpio_a); - gpio_free(pdata->gpio_b); - - input_unregister_device(encoder->input); - kfree(encoder); - - if (!dev_get_platdata(&pdev->dev)) - kfree(pdata); - return 0; }