Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1082120imu; Fri, 25 Jan 2019 17:17:29 -0800 (PST) X-Google-Smtp-Source: ALg8bN4l25O1TjWWqYvQ6an7HgqX6b23A6KM9fdYOqiMksm5SX03eX9xDbJTIEoUQE1wSJDqAPwk X-Received: by 2002:a63:5a57:: with SMTP id k23mr11905430pgm.5.1548465449202; Fri, 25 Jan 2019 17:17:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548465449; cv=none; d=google.com; s=arc-20160816; b=wVxiE2hJ4M17MuhuSwdjkz6MWnvAoBa9199QbPHY182276BhqlpzSCr5xFTG9ah7ON z3L+Fa9eqhAJ/oa38bZKGw2BYXKM5y7FTotgYpqbMfAs41BuAZPJpBgB6JYPaCBgd4rQ Xuml+/9XQWLHMK38666aCzY+JTvZG9/EjoC7m7yBhmK/PV0tiCyLdi9EGiUdnpCScvyK Ku4CwYHR/MCMPrDmp7W07QuE94C2sE/nBA7a8znjq0HEfHaYWZNa2sAEC60GduSiJuc+ JKKVvN5fA8onKERaLDRbezfGbnH0oKddZDQiVPhQyFrXw2yeYgSlOmOiWoWA0+Owl9VV BdFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=zFUPyiecKChK/e0u1mqAoiYkxRi+n9AALMCCHtZq21E=; b=PJe0S9knZOBrh0YeK547gWwA+ZQtcxw0Dsh/uYVU0T/AacNV4G8lYHjwxAA06KgXgd ZOv6lA+g6xGhZbUXxiAE6mkr6k+9raQIuSZUNrq0BWZm9JgVzGuqqjbUfhwmFIolSvdx rkvLLCek65pphDsm+Cwyht6tcCuRJl5Aj9192RbGulXuJwyfEyNDlEVtP/4sgt3t861Y xUvqcvIiVgazQsVUcEUxLDCZxDpjGXlrCW23AwUOG2lYw0V7ZLvToTYt57ZJjV6fanXI c1YiMmGUUOdSiaszn/T1w9fsmYwRvs4MsQjCqKGbKaKdQAvOcdwoNGPtbfC1grDcW/+z TTzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eS1QWiGC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h5si27107007pfg.233.2019.01.25.17.17.13; Fri, 25 Jan 2019 17:17:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eS1QWiGC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726589AbfAZBRI (ORCPT + 99 others); Fri, 25 Jan 2019 20:17:08 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:45465 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725550AbfAZBRH (ORCPT ); Fri, 25 Jan 2019 20:17:07 -0500 Received: by mail-pf1-f193.google.com with SMTP id g62so5498286pfd.12; Fri, 25 Jan 2019 17:17:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=zFUPyiecKChK/e0u1mqAoiYkxRi+n9AALMCCHtZq21E=; b=eS1QWiGCW57PTbymz4aexvUE8gvvCdzeS0ozTrSoN3cGtux9Yj5RIlgWhqn37EDhjB xCu6nLE6s6COoGqGGxijWE07wutpgvfYCc4ldY7qtKdIeLYfH09Dpx5NEiZ2FCYf9KVX FSqlZ6NZGmpNcw2IIAITyg05GKuSricdSSTfuwMcfZaLNrDm/668HtyB40HuCcgrikmj IiBBH8pVViFpssKoxF5u8n7+l+L3Y6wqfm1Y+qRep8qA0tXuM0WtfEVmAs7a/lJlblZk 78zwHhsg6K93jZ97VjlYFxSVKz4jqr6RQZD0HtV1wXPYXj3oM6PM2yvqCu5SlR/+Z4w6 a45A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=zFUPyiecKChK/e0u1mqAoiYkxRi+n9AALMCCHtZq21E=; b=Gxkdv+ZHqgFFp0HrL0oO+KRGH2gf6s5eGooGfH6HL6Ium05xklTp9sPe5ftYEJe3Lp Ab7b7b82Dl6zXbHMNreKsNTbT53f5+CMM42oodlfgO+P6g9T1ctVI3qvil52g2UEo/v+ D1akZkvYiPLZ1EWJr2CsXu0lWDSTs0CIvqmZb2+zRm97muKSS5TwBmAx+qx8vG2o53Y0 +hSmr1PdGuuFwrak6qxY9zJOQs5fqnIdTzZDEiCK0d4h4Ki5elfUfBud8EMMz4txPBoT Ba5vstm1oqHAdCAlu64/LuxHdXEUWMpy6fgovVsMEILkRf3W1bDLn4EzMW9Tcej49TdY Dq1A== X-Gm-Message-State: AJcUukeVebGzNo/6rl6faI+eI2Qsnr4I9jWXtBSZuxMKe3so1ThjJBsu BI3z1x5t3jWqzb+snUSOi8I= X-Received: by 2002:a63:ed42:: with SMTP id m2mr12048524pgk.147.1548465426156; Fri, 25 Jan 2019 17:17:06 -0800 (PST) Received: from dtor-ws ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id d25sm36516349pfe.40.2019.01.25.17.17.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 Jan 2019 17:17:05 -0800 (PST) Date: Fri, 25 Jan 2019 17:17:02 -0800 From: Dmitry Torokhov To: =?utf-8?B?UGF3ZcWC?= Chmiel Cc: robh+dt@kernel.org, mark.rutland@arm.com, mchehab+samsung@kernel.org, colyli@suse.de, ckeepax@opensource.wolfsonmicro.com, andrew.smirnov@gmail.com, arnd@arndb.de, xiaotong.lu@spreadtrum.com, xc-racer2@live.ca, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH 1/4] input: misc: gp2a: Use managed resource helpers Message-ID: <20190126011702.GB212026@dtor-ws> References: <20190125175045.22576-1-pawel.mikolaj.chmiel@gmail.com> <20190125175045.22576-2-pawel.mikolaj.chmiel@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190125175045.22576-2-pawel.mikolaj.chmiel@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 25, 2019 at 06:50:42PM +0100, Paweł Chmiel wrote: > From: Jonathan Bakker > > Simplify cleanup of failures by using managed resource helpers > > Signed-off-by: Jonathan Bakker > Signed-off-by: Paweł Chmiel > --- > drivers/input/misc/gp2ap002a00f.c | 37 ++++++++++--------------------- > 1 file changed, 12 insertions(+), 25 deletions(-) > > diff --git a/drivers/input/misc/gp2ap002a00f.c b/drivers/input/misc/gp2ap002a00f.c > index c6a29e57b5e4..79c8c4c56d1a 100644 > --- a/drivers/input/misc/gp2ap002a00f.c > +++ b/drivers/input/misc/gp2ap002a00f.c > @@ -138,14 +138,15 @@ static int gp2a_probe(struct i2c_client *client, > return error; > } > > - error = gpio_request_one(pdata->vout_gpio, GPIOF_IN, GP2A_I2C_NAME); > + error = devm_gpio_request_one(&client->dev, pdata->vout_gpio, > + GPIOF_IN, GP2A_I2C_NAME); > if (error) > goto err_hw_shutdown; > > - dt = kzalloc(sizeof(struct gp2a_data), GFP_KERNEL); > + dt = devm_kzalloc(&client->dev, sizeof(struct gp2a_data), GFP_KERNEL); > if (!dt) { > error = -ENOMEM; > - goto err_free_gpio; > + goto err_hw_shutdown; > } > > dt->pdata = pdata; > @@ -153,12 +154,12 @@ static int gp2a_probe(struct i2c_client *client, > > error = gp2a_initialize(dt); > if (error < 0) > - goto err_free_mem; > + goto err_hw_shutdown; > > - dt->input = input_allocate_device(); > + dt->input = devm_input_allocate_device(&client->dev); > if (!dt->input) { > error = -ENOMEM; > - goto err_free_mem; > + goto err_hw_shutdown; > } > > input_set_drvdata(dt->input, dt); > @@ -171,19 +172,18 @@ static int gp2a_probe(struct i2c_client *client, > > input_set_capability(dt->input, EV_SW, SW_FRONT_PROXIMITY); > > - error = request_threaded_irq(client->irq, NULL, gp2a_irq, > - IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | > - IRQF_ONESHOT, > - GP2A_I2C_NAME, dt); > + error = devm_request_threaded_irq(&client->dev, client->irq, NULL, > + gp2a_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | > + IRQF_ONESHOT, GP2A_I2C_NAME, dt); > if (error) { > dev_err(&client->dev, "irq request failed\n"); > - goto err_free_input_dev; > + goto err_hw_shutdown; > } > > error = input_register_device(dt->input); > if (error) { > dev_err(&client->dev, "device registration failed\n"); > - goto err_free_irq; > + goto err_hw_shutdown; > } > > device_init_wakeup(&client->dev, pdata->wakeup); > @@ -191,14 +191,6 @@ static int gp2a_probe(struct i2c_client *client, > > return 0; > > -err_free_irq: > - free_irq(client->irq, dt); > -err_free_input_dev: > - input_free_device(dt->input); > -err_free_mem: > - kfree(dt); > -err_free_gpio: > - gpio_free(pdata->vout_gpio); > err_hw_shutdown: > if (pdata->hw_shutdown) > pdata->hw_shutdown(client); > @@ -210,12 +202,7 @@ static int gp2a_remove(struct i2c_client *client) > struct gp2a_data *dt = i2c_get_clientdata(client); > const struct gp2a_platform_data *pdata = dt->pdata; > > - free_irq(client->irq, dt); > - > input_unregister_device(dt->input); You do not need explicitly unregister input device if it is managed (allocated with devm). > - kfree(dt); > - > - gpio_free(pdata->vout_gpio); > > if (pdata->hw_shutdown) > pdata->hw_shutdown(client); This is however is wrong, as you can't shutdown hardware before disapling/freeing IRQ, etc. Given that there are no users of gp2a_platform_data in kernel I'd recommend creating a preparatory patch removing platform data support from the driver. Thanks. -- Dmitry