From patchwork Wed Jan 9 09:22:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sachin Kamat X-Patchwork-Id: 13942 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 02C2923E02 for ; Wed, 9 Jan 2013 09:31:39 +0000 (UTC) Received: from mail-vb0-f43.google.com (mail-vb0-f43.google.com [209.85.212.43]) by fiordland.canonical.com (Postfix) with ESMTP id 68F21A18F7C for ; Wed, 9 Jan 2013 09:31:38 +0000 (UTC) Received: by mail-vb0-f43.google.com with SMTP id fs19so1320813vbb.2 for ; Wed, 09 Jan 2013 01:31:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=i2hgFL5C2rxdWpftZ3XTEcZZFI6htoEjaDwIGoIch8Y=; b=RJVlC4Xn15TLnsNjFHRpW3J6pwIpCxyh8mMGRPTomdKkA7y3qqpZ9AFjR8dJwVkc4n 139losJyHxmub1p8OVMEfSHQAOauwqHj+ZxzH1XoF70Tpx63RR3h4PuFZT4MIQENQrjZ o65JwwKH9BoAzthznPyBmHi2RmF1zZsV2XWHEFR3yptxmhCtJkPPEQHG2jgdSNGslM/A 7JqACKy9ZRiFO0zBmwHmkX3lH6JTbOJlkWq8IXoQiomxrZQjpT7hODwq2yfG/WbIRbjN CpmJ5MyRZjtAV1kc0Z+3Ed+VKa0/iEgBtusoE+SDjE82i3j6qRHdgxJmTD74KO3z7imk auUA== X-Received: by 10.220.157.9 with SMTP id z9mr89003515vcw.45.1357723897779; Wed, 09 Jan 2013 01:31:37 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.145.101 with SMTP id st5csp4815veb; Wed, 9 Jan 2013 01:31:37 -0800 (PST) X-Received: by 10.68.233.7 with SMTP id ts7mr205325121pbc.136.1357723896544; Wed, 09 Jan 2013 01:31:36 -0800 (PST) Received: from mail-da0-f48.google.com (mail-da0-f48.google.com [209.85.210.48]) by mx.google.com with ESMTPS id yf4si65472688pbc.231.2013.01.09.01.31.36 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 09 Jan 2013 01:31:36 -0800 (PST) Received-SPF: neutral (google.com: 209.85.210.48 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) client-ip=209.85.210.48; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.48 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) smtp.mail=sachin.kamat@linaro.org Received: by mail-da0-f48.google.com with SMTP id k18so661113dae.7 for ; Wed, 09 Jan 2013 01:31:36 -0800 (PST) X-Received: by 10.66.84.10 with SMTP id u10mr189019951pay.24.1357723896039; Wed, 09 Jan 2013 01:31:36 -0800 (PST) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id wg3sm41322390pbc.28.2013.01.09.01.31.33 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 09 Jan 2013 01:31:35 -0800 (PST) From: Sachin Kamat To: linux-input@vger.kernel.org Cc: dmitry.torokhov@gmail.com, sachin.kamat@linaro.org, patches@linaro.org, Joonyoung Shim Subject: [PATCH v3] Input: mms114: Use devm_* APIs Date: Wed, 9 Jan 2013 14:52:33 +0530 Message-Id: <1357723353-11144-1-git-send-email-sachin.kamat@linaro.org> X-Mailer: git-send-email 1.7.4.1 X-Gm-Message-State: ALoCoQnWGrhoRYgK8uqM2dssCSPnc9+KdxcLdqAfka+bRM3JfiAOGH5S5XoFJxT3ZO5by50ZR2C3 devm_* APIs are device managed and make the exit and clean up code simpler. Signed-off-by: Sachin Kamat Cc: Joonyoung Shim Acked-by: Laxman Dewangan --- Compile tested against linux-next (20130109). Changes since: v2: Addressed review comments. v1: Removed input_unregister_device() call. --- drivers/input/touchscreen/mms114.c | 54 ++++++++++------------------------- 1 files changed, 16 insertions(+), 38 deletions(-) diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c index 98841d8..a9cb475 100644 --- a/drivers/input/touchscreen/mms114.c +++ b/drivers/input/touchscreen/mms114.c @@ -429,12 +429,12 @@ static int mms114_probe(struct i2c_client *client, return -ENODEV; } - data = kzalloc(sizeof(struct mms114_data), GFP_KERNEL); - input_dev = input_allocate_device(); + data = devm_kzalloc(&client->dev, sizeof(struct mms114_data), + GFP_KERNEL); + input_dev = devm_input_allocate_device(&client->dev); if (!data || !input_dev) { dev_err(&client->dev, "Failed to allocate memory\n"); - error = -ENOMEM; - goto err_free_mem; + return -ENOMEM; } data->client = client; @@ -466,57 +466,36 @@ static int mms114_probe(struct i2c_client *client, input_set_drvdata(input_dev, data); i2c_set_clientdata(client, data); - data->core_reg = regulator_get(&client->dev, "avdd"); + data->core_reg = devm_regulator_get(&client->dev, "avdd"); if (IS_ERR(data->core_reg)) { error = PTR_ERR(data->core_reg); dev_err(&client->dev, "Unable to get the Core regulator (%d)\n", error); - goto err_free_mem; + return error; } - data->io_reg = regulator_get(&client->dev, "vdd"); + data->io_reg = devm_regulator_get(&client->dev, "vdd"); if (IS_ERR(data->io_reg)) { error = PTR_ERR(data->io_reg); dev_err(&client->dev, "Unable to get the IO regulator (%d)\n", error); - goto err_core_reg; + return error; } - error = request_threaded_irq(client->irq, NULL, mms114_interrupt, - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "mms114", data); + error = devm_request_threaded_irq(&client->dev, client->irq, NULL, + mms114_interrupt, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, + dev_name(&client->dev), data); if (error) { dev_err(&client->dev, "Failed to register interrupt\n"); - goto err_io_reg; + return error; } disable_irq(client->irq); error = input_register_device(data->input_dev); - if (error) - goto err_free_irq; - - return 0; - -err_free_irq: - free_irq(client->irq, data); -err_io_reg: - regulator_put(data->io_reg); -err_core_reg: - regulator_put(data->core_reg); -err_free_mem: - input_free_device(input_dev); - kfree(data); - return error; -} - -static int mms114_remove(struct i2c_client *client) -{ - struct mms114_data *data = i2c_get_clientdata(client); - - free_irq(client->irq, data); - regulator_put(data->io_reg); - regulator_put(data->core_reg); - input_unregister_device(data->input_dev); - kfree(data); + if (error) { + dev_err(&client->dev, "Failed to register device\n"); + return error; + } return 0; } @@ -590,7 +569,6 @@ static struct i2c_driver mms114_driver = { .of_match_table = of_match_ptr(mms114_dt_match), }, .probe = mms114_probe, - .remove = mms114_remove, .id_table = mms114_id, };