From patchwork Thu Feb 26 01:48:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 5886861 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 0274D9F37F for ; Thu, 26 Feb 2015 01:48:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2304E202F0 for ; Thu, 26 Feb 2015 01:48:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 34E7220274 for ; Thu, 26 Feb 2015 01:48:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753325AbbBZBsY (ORCPT ); Wed, 25 Feb 2015 20:48:24 -0500 Received: from mail-ie0-f173.google.com ([209.85.223.173]:37222 "EHLO mail-ie0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752907AbbBZBsX (ORCPT ); Wed, 25 Feb 2015 20:48:23 -0500 Received: by iecrl12 with SMTP id rl12so10255107iec.4; Wed, 25 Feb 2015 17:48:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=iPdsIbyxTc9cP34m3plIuxTagcOgnX29zXGJk2eoZ/I=; b=JSp9GKsGpIM/HCVmyt4gvqZ5mpegKHx7rTz7GUrXdZw9MJyCuaYgrZ498GkpLyIL8g SXXb2a6V313S713XVzP8Yov6VVJMieT7+bdKBPbMeCKk319r87lpgpxw9NmLmOOJuG6e zfZkZKLPNIWwvWs7UC5RB7pS6SmBkHz993FkFrze8f1Mev5qxCgXVHbl8jO3Z+VkN9a2 n83eM8A1f3xD3IPHYXrYjZ6b5llHRWdDCoowOXieUMfl0q1Rr8idYjznsl1DNv0OpJPr nmJ6GcM/kykUeitaWVYKkx/vJcQx18n73iKBb4vbWeXGYnN0LRs2sQxztUK79/NSyUHb /RIw== X-Received: by 10.43.142.4 with SMTP id jg4mr7531785icc.42.1424915302667; Wed, 25 Feb 2015 17:48:22 -0800 (PST) Received: from dtor-ws ([2620:0:1000:1301:c967:ce0:fd57:c2f2]) by mx.google.com with ESMTPSA id e5sm26720823ioi.2.2015.02.25.17.48.20 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 25 Feb 2015 17:48:21 -0800 (PST) Date: Wed, 25 Feb 2015 17:48:18 -0800 From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Stefan Sauer , linux-kernel@vger.kernel.org Subject: [PATCH] Input: mma8450 - convert to using managed resources Message-ID: <20150226014818.GA2469@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 This simplifies error handling and device removal code. Also let's get rid of setting driver's owner since i2c core does it for us. Signed-off-by: Dmitry Torokhov --- Note that the following removal was intentional as devm_input_allocate_polled_device() does this for us: - idev->input->dev.parent = &c->dev; drivers/input/misc/mma8450.c | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c index 9822877..19c7357 100644 --- a/drivers/input/misc/mma8450.c +++ b/drivers/input/misc/mma8450.c @@ -174,12 +174,13 @@ static int mma8450_probe(struct i2c_client *c, struct mma8450 *m; int err; - m = kzalloc(sizeof(struct mma8450), GFP_KERNEL); - idev = input_allocate_polled_device(); - if (!m || !idev) { - err = -ENOMEM; - goto err_free_mem; - } + m = devm_kzalloc(&c->dev, sizeof(*m), GFP_KERNEL); + if (!m) + return -ENOMEM; + + idev = devm_input_allocate_polled_device(&c->dev); + if (!idev) + return -ENOMEM; m->client = c; m->idev = idev; @@ -187,7 +188,6 @@ static int mma8450_probe(struct i2c_client *c, idev->private = m; idev->input->name = MMA8450_DRV_NAME; idev->input->id.bustype = BUS_I2C; - idev->input->dev.parent = &c->dev; idev->poll = mma8450_poll; idev->poll_interval = POLL_INTERVAL; idev->poll_interval_max = POLL_INTERVAL_MAX; @@ -202,29 +202,12 @@ static int mma8450_probe(struct i2c_client *c, err = input_register_polled_device(idev); if (err) { dev_err(&c->dev, "failed to register polled input device\n"); - goto err_free_mem; + return err; } i2c_set_clientdata(c, m); return 0; - -err_free_mem: - input_free_polled_device(idev); - kfree(m); - return err; -} - -static int mma8450_remove(struct i2c_client *c) -{ - struct mma8450 *m = i2c_get_clientdata(c); - struct input_polled_dev *idev = m->idev; - - input_unregister_polled_device(idev); - input_free_polled_device(idev); - kfree(m); - - return 0; } static const struct i2c_device_id mma8450_id[] = { @@ -242,11 +225,9 @@ MODULE_DEVICE_TABLE(of, mma8450_dt_ids); static struct i2c_driver mma8450_driver = { .driver = { .name = MMA8450_DRV_NAME, - .owner = THIS_MODULE, .of_match_table = mma8450_dt_ids, }, .probe = mma8450_probe, - .remove = mma8450_remove, .id_table = mma8450_id, };