From patchwork Tue Feb 28 22:46:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9597103 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7115960471 for ; Tue, 28 Feb 2017 22:55:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 640BF20246 for ; Tue, 28 Feb 2017 22:55:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58FE82816B; Tue, 28 Feb 2017 22:55:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAAC320246 for ; Tue, 28 Feb 2017 22:55:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751547AbdB1Wzr (ORCPT ); Tue, 28 Feb 2017 17:55:47 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:36545 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750957AbdB1Wzq (ORCPT ); Tue, 28 Feb 2017 17:55:46 -0500 Received: by mail-pg0-f65.google.com with SMTP id 25so3292744pgy.3; Tue, 28 Feb 2017 14:52:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vfocB+et4G8bUpCdQfr+Py0e5A0TyZtO5sh0WUVPpo8=; b=jaCHORT+QP1Al2XQkIhN5FMbR1OXi8fxK3kUYEoDgaEwoqhKz1Cx9Lq+3Nfes4aktU Afn2/4ZveSuCjYMk1IaRlGFp3rHKCFJcnxq2H8agtONdOBwAL8A13LJodx5iaP/FgyiI 4KQSnTn8Lm16a8TM0Ien6ne5P4tGqh/yZ6yY5taZy0OG3rAXOKMcQEkaD5IyCarSeQoi 2heXjCQQ0dlGoTZB2NzjPDZS562hVGFU2Jb4RODCH/WmqDBikwZ5qgSIx7ATiIKBX25V cF9Od2zKeVn/ydjTEoJ9wLQo9/22zdH4Kh/lV2tRfdn1L1CuxhsB/lzjvCDrZJjJU1zu jtAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vfocB+et4G8bUpCdQfr+Py0e5A0TyZtO5sh0WUVPpo8=; b=UuVh+rzpneZ8NXN4jKHKw7BATVMh3IOQ9lhc8H1wFKkxAim8I5QgeFO49+TtEPo9Kf EjWF081YMEeo300HaeSGLMmqItS0mKr9u49Ov4dKMPkf988H8N1Sn4jrxDxGHp6i4csV MitFgS8zLNyolnvASrZNevJSLTW176DJqJs8GHHBhTSIPtfzaS/+IfFa5Kq8daJ0f8BJ zCe8XuUJq3KjrxsTXi6b3W++tkPY19opf9Fv8KzN98DBJ2Q3/ZJfAIEVgIjcxjyL61tf kx6HRqlhioaKK8OC+ZCh4s1TRoCYZRAvN4flbYcUDGLyGFReQYTmlQ27ABq8wnClPagO 8t2Q== X-Gm-Message-State: AMke39kdF4qbU399WT8rXt40Y5CVVyutrz4dLwI/lPHJs0hcTWKMrbF5vUp6AxIvumO1rA== X-Received: by 10.99.67.6 with SMTP id q6mr5110590pga.156.1488321998243; Tue, 28 Feb 2017 14:46:38 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([172.22.152.34]) by smtp.gmail.com with ESMTPSA id u80sm6155359pgb.32.2017.02.28.14.46.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Feb 2017 14:46:37 -0800 (PST) From: Dmitry Torokhov To: Daniel Mack Cc: Haojian Zhuang , Robert Jarzmik , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH 05/10] Input: eeti-ts - switch to using managed resources Date: Tue, 28 Feb 2017 14:46:27 -0800 Message-Id: <20170228224632.3401-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog In-Reply-To: <20170228224632.3401-1-dmitry.torokhov@gmail.com> References: <20170228224632.3401-1-dmitry.torokhov@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Using devm_* APIs simpifies error handling and device teardown. Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/eeti_ts.c | 70 ++++++++++++------------------------- 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/drivers/input/touchscreen/eeti_ts.c b/drivers/input/touchscreen/eeti_ts.c index b472e0e467e8..e99e4fec93f5 100644 --- a/drivers/input/touchscreen/eeti_ts.c +++ b/drivers/input/touchscreen/eeti_ts.c @@ -157,13 +157,14 @@ static void eeti_ts_close(struct input_dev *dev) } static int eeti_ts_probe(struct i2c_client *client, - const struct i2c_device_id *idp) + const struct i2c_device_id *idp) { - struct eeti_ts_platform_data *pdata = dev_get_platdata(&client->dev); + struct device *dev = &client->dev; + struct eeti_ts_platform_data *pdata = dev_get_platdata(dev); struct eeti_ts *eeti; struct input_dev *input; unsigned int irq_flags; - int err = -ENOMEM; + int error; /* * In contrast to what's described in the datasheet, there seems @@ -172,18 +173,18 @@ static int eeti_ts_probe(struct i2c_client *client, * for interrupts to occur. */ - eeti = kzalloc(sizeof(*eeti), GFP_KERNEL); + eeti = devm_kzalloc(dev, sizeof(*eeti), GFP_KERNEL); if (!eeti) { - dev_err(&client->dev, "failed to allocate driver data\n"); + dev_err(dev, "failed to allocate driver data\n"); return -ENOMEM; } mutex_init(&eeti->mutex); - input = input_allocate_device(); + input = devm_input_allocate_device(dev); if (!input) { - dev_err(&client->dev, "Failed to allocate input device.\n"); - goto err1; + dev_err(dev, "Failed to allocate input device.\n"); + return -ENOMEM; } input_set_capability(input, EV_KEY, BTN_TOUCH); @@ -194,7 +195,6 @@ static int eeti_ts_probe(struct i2c_client *client, input->name = client->name; input->id.bustype = BUS_I2C; - input->dev.parent = &client->dev; input->open = eeti_ts_open; input->close = eeti_ts_close; @@ -203,9 +203,10 @@ static int eeti_ts_probe(struct i2c_client *client, eeti->irq_gpio = pdata->irq_gpio; eeti->irq = gpio_to_irq(pdata->irq_gpio); - err = gpio_request_one(pdata->irq_gpio, GPIOF_IN, client->name); - if (err < 0) - goto err1; + error = devm_gpio_request_one(dev, pdata->irq_gpio, GPIOF_IN, + client->name); + if (error) + return error; eeti->irq_active_high = pdata->irq_active_high; @@ -216,15 +217,16 @@ static int eeti_ts_probe(struct i2c_client *client, i2c_set_clientdata(client, eeti); input_set_drvdata(input, eeti); - err = input_register_device(input); - if (err) - goto err2; + error = input_register_device(input); + if (error) + return error; - err = request_irq(eeti->irq, eeti_ts_isr, irq_flags, - client->name, eeti); - if (err) { - dev_err(&client->dev, "Unable to request touchscreen IRQ.\n"); - goto err3; + error = devm_request_irq(dev, eeti->irq, eeti_ts_isr, irq_flags, + client->name, eeti); + if (error) { + dev_err(dev, "Unable to request touchscreen IRQ: %d\n", + error); + return error; } /* @@ -234,33 +236,6 @@ static int eeti_ts_probe(struct i2c_client *client, eeti_ts_stop(eeti); return 0; - -err3: - input_unregister_device(input); - input = NULL; /* so we dont try to free it below */ -err2: - gpio_free(pdata->irq_gpio); -err1: - input_free_device(input); - kfree(eeti); - return err; -} - -static int eeti_ts_remove(struct i2c_client *client) -{ - struct eeti_ts *eeti = i2c_get_clientdata(client); - - free_irq(eeti->irq, eeti); - /* - * eeti_ts_stop() leaves IRQ disabled. We need to re-enable it - * so that device still works if we reload the driver. - */ - enable_irq(eeti->irq); - - input_unregister_device(eeti->input); - kfree(eeti); - - return 0; } static int __maybe_unused eeti_ts_suspend(struct device *dev) @@ -315,7 +290,6 @@ static struct i2c_driver eeti_ts_driver = { .pm = &eeti_ts_pm, }, .probe = eeti_ts_probe, - .remove = eeti_ts_remove, .id_table = eeti_ts_id, };