From patchwork Tue Jul 26 01:29:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanlong Gao X-Patchwork-Id: 1006932 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6Q1V6Ht007504 for ; Tue, 26 Jul 2011 01:31:06 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752605Ab1GZBbF (ORCPT ); Mon, 25 Jul 2011 21:31:05 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:58517 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752496Ab1GZBbE (ORCPT ); Mon, 25 Jul 2011 21:31:04 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 80C7017012F; Tue, 26 Jul 2011 09:30:57 +0800 (CST) Received: from mailserver.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id p6Q1UuG2014444; Tue, 26 Jul 2011 09:30:57 +0800 Received: from [10.167.225.68] ([10.167.225.68]) by mailserver.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2011072609300406-11898 ; Tue, 26 Jul 2011 09:30:04 +0800 Message-ID: <4E2E1897.9020808@cn.fujitsu.com> Date: Tue, 26 Jul 2011 09:29:59 +0800 From: Wanlong Gao Reply-To: gaowanlong@cn.fujitsu.com Organization: FNST User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110322 Red Hat/3.1.9-3.el6_0 Thunderbird/3.1.9 MIME-Version: 1.0 To: Dmitry Torokhov CC: Mark Brown , Wanlong Gao , Greg KH , linux-input@vger.kernel.org Subject: Re: [PATCH] drivers:input:set driver data to NULL for pcap_keys References: <1311176068-9934-1-git-send-email-wanlong.gao@gmail.com> <20110725083048.GD22937@core.coreip.homeip.net> <4E2D33E3.9090408@cn.fujitsu.com> <20110725152106.GB23356@suse.de> <1311608069.3262.8.camel@Allen> <20110725181916.GB6876@core.coreip.homeip.net> <20110725182928.GB1175@sirena.org.uk> <20110725183746.GD6876@core.coreip.homeip.net> In-Reply-To: <20110725183746.GD6876@core.coreip.homeip.net> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-07-26 09:30:04, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-07-26 09:30:04, Serialize complete at 2011-07-26 09:30:04 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 26 Jul 2011 01:31:06 +0000 (UTC) On 07/26/2011 02:37 AM, Dmitry Torokhov wrote: > On Mon, Jul 25, 2011 at 07:29:28PM +0100, Mark Brown wrote: >> On Mon, Jul 25, 2011 at 11:19:16AM -0700, Dmitry Torokhov wrote: >> >>> Right, like i2c bus we could just have platform core clean up platform >>> drvdata pointer after calling ->remove() and also if ->probe() errors >>> out. >> >> I2C doesn't do this (at least not any more). >> > > Sure does. See drivers/i2c/i2c-core.c::i2c_device_probe() and > i2c_device_remove(). Yeah, I see it. Sure i2c does. Let the Core to do the pointer's clean up is very good idea. So, Dmitry, do you means this ? Signed-off-by: Wanlong Gao --- drivers/base/platform.c | 30 ++++++++++++++++++++++++++++-- 1 files changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 6040717..349e71b 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -405,8 +405,21 @@ static int platform_drv_probe(struct device *_dev) { struct platform_driver *drv = to_platform_driver(_dev->driver); struct platform_device *dev = to_platform_device(_dev); + int status; - return drv->probe(dev); + if (!dev) + return 0; + + if (!drv->probe) + return -ENODEV; + + dev_dbg(_dev, "probe\n"); + + status = drv->probe(dev); + if (status) + platform_set_drvdata(dev, NULL); + + return status; } static int platform_drv_probe_fail(struct device *_dev) @@ -418,8 +431,21 @@ static int platform_drv_remove(struct device *_dev) { struct platform_driver *drv = to_platform_driver(_dev->driver); struct platform_device *dev = to_platform_device(_dev); + int status; + + if (!dev) + return 0; + + if (drv->remove) { + dev_dbg(_dev, "remove\n"); + status = drv->remove(dev); + } else { + status = 0; + } + if (status == 0) + platform_set_drvdata(dev, NULL); - return drv->remove(dev); + return status; } static void platform_drv_shutdown(struct device *_dev)