Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4349595ybi; Tue, 11 Jun 2019 05:19:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcBHhWlyG9IfniFc00QJO7K2tyaRVItKqI7D39SiPkv4Ac/xNPlXUx0vENU0eIsLovtHDT X-Received: by 2002:a62:198e:: with SMTP id 136mr77155266pfz.180.1560255560808; Tue, 11 Jun 2019 05:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560255560; cv=none; d=google.com; s=arc-20160816; b=gfaDSXKfF8jJ6neYi/ZvDlnk/aedqdGfriDXIxSgM7QzPO2ChVYLLN2jXWXdD50w4W Ev/UEyqNljEyHLFfTa3RV2rLmaBKVgVGiESFtLKX1pPcXThgysr0/7E4lcQrYESghGwc SfZb9hHS4oJ46ln2udDXKiRIqscQMNYFKyhwiD4dNL+z0ic9a//2b5Ycq2ef2QPJUZum rCAdVQbmrr4DZ3yi/csYfQQ0ZANx8C9SmlcCTQnLrsjiRDBhfJnfWAvvyegHC2c2xFPp 65UYyG3ACZ+AEW1gLMAKEzRxJ2CJNW/jI311tV/p2WyvD1k8levIN10XzkeqvOwDL+5X L9oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=FbfnQ+vyxLkky9Y2QN7piyoWYG4+Tbz+gCXalexofB0=; b=k1LGBKR4rqQR+My56Ym4dVUrYSR7F3PQPpGOdue3f5NSADobKcquvcJvTpciJrRjVA s1aZTnzkmWh3rsJMIkbfgSlEC7ZhxFoZOLlCqwl6B3PxlJrRpo5EedzqhSrXvaPzE0nb JxwkF00lRFkDHSzYSfEwZc/zKS14a0hJ6l1CS1SLnk0UaQGfKsl6iCU2YCa/8RArS0Ji RbOMl3KGkU2usKq3xwhIwRTWwrr4WXXVvvV/97LqBok6qxNYmxh6Aip3DUdsu3dbz0qr g81PCwC59g/INRC9Z4SDJOB4aa0sLeTExbwY20cGeMmYS5Q9L61//07+XP0q7J/yE2yK hBtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ZiSHqTWD; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bc10si12644099plb.43.2019.06.11.05.19.06; Tue, 11 Jun 2019 05:19:20 -0700 (PDT) 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=fail header.i=@gmail.com header.s=20161025 header.b=ZiSHqTWD; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388656AbfFKLCG (ORCPT + 99 others); Tue, 11 Jun 2019 07:02:06 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37991 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388629AbfFKLCF (ORCPT ); Tue, 11 Jun 2019 07:02:05 -0400 Received: by mail-pg1-f193.google.com with SMTP id v11so6770968pgl.5; Tue, 11 Jun 2019 04:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=FbfnQ+vyxLkky9Y2QN7piyoWYG4+Tbz+gCXalexofB0=; b=ZiSHqTWDMwZI2ncl7CzllBTrpA5z72DaPReLrAyt7+0qSTaxxWRNMhzOBWGr1JI56Y qi9RpektgZCibhRtOn+ktx8REAZo10rR/7Up+FAMlSZeEPA4XYnHblcrAp13yNegjr6+ mhPEcJrCIK3boLuR4OMqXbHALynvgH5NNj8SlgpiV0XTMX6sYx8PZxF3iudh0UoVNbFv d8U1bEHaqVjqSCV7f7+GCjQT2r2MN5gGUr9wHhOB1csBBZkTvK32Z3w3iOBKWxpgZNnL 1mJuREZJYHWIY7SdEe+Lcq5ivHJo5SSlSHJga6OAJdxOH09pR4eeN/RfIBkNPEtAaMVX q7Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=FbfnQ+vyxLkky9Y2QN7piyoWYG4+Tbz+gCXalexofB0=; b=h/EmZevCOJZQeKnyOeKrZRbqCVh7YMmwlNgMujsKN3dbc92jFY85vYKVTo0b+otLyU iBcyMXgsF87DQWzfnfTvL84TlcrL81405dBLSLxZfPL5llUafZKcjgtZ4Au+s4+oIsVt 5+DiFT9BEwG4gLtvoiBw1DTEbcet9zMsEdeCJkTvxYsjEvoMefzuCYZ+k1iox5rp0xE+ eT7hbwnPgnlgghw1Zf5jts1r/uIzL++ZkLCquX/pEpGS0KRj95w4YXqu4LxFw2YFaiU4 4murETaBsq7cPFhnG7TZHmrPEWmgcXoJl5G/MlxYQIzgtczyOOCux4kKO5ffz89Oyb7U iXMA== X-Gm-Message-State: APjAAAXtaTKD5/YWvoHx69sfQH1qXoMprM7L26eN4AqLlzVnwvaDyAUi GcGerOtbNwjZ4y76yZq01U0gd5p3 X-Received: by 2002:a63:cc4e:: with SMTP id q14mr19621119pgi.84.1560250924091; Tue, 11 Jun 2019 04:02:04 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id e4sm19432780pgi.80.2019.06.11.04.02.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Jun 2019 04:02:03 -0700 (PDT) Subject: Re: [PATCH v2 4/4] watchdog: jz4740: Make probe function __init_or_module To: Christophe Leroy , Paul Cercueil Cc: Wim Van Sebroeck , od@zcrc.me, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190607162429.17915-1-paul@crapouillou.net> <20190607162429.17915-5-paul@crapouillou.net> <0dc0fd0a-54fc-5d70-af78-1874b5ece418@c-s.fr> <1559987821.1815.0@crapouillou.net> <78ef0273-5ec6-f522-428a-8429f40684ca@c-s.fr> From: Guenter Roeck Message-ID: Date: Tue, 11 Jun 2019 04:02:02 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <78ef0273-5ec6-f522-428a-8429f40684ca@c-s.fr> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/10/19 10:16 PM, Christophe Leroy wrote: > Hi Paul, > > Le 08/06/2019 à 11:57, Paul Cercueil a écrit : >> Hi Christophe, >> >> Le sam. 8 juin 2019 à 9:51, Christophe Leroy a écrit : >>> Hi Paul, >>> >>> Le 07/06/2019 à 18:24, Paul Cercueil a écrit : >>>> This allows the probe function to be dropped after the kernel finished >>>> its initialization, in the case where the driver was not compiled as a >>>> module. >>> >>> I'm not sure that's what  __init_or_module flag does. >>> >>> As far as I understand, this flag makes the function being dropped only when the kernel is built without modules support, ie without CONFIG_MODULES. See https://elixir.bootlin.com/linux/latest/source/include/linux/module.h#L145 >> >> So it doesn't depend on the driver being built-in or compiled as a module? > > No it doesn't. This flag is for built-in functions that are needed by init and modules init. If the kernel doesn't support modules, it can drop the function after init. If the kernel supports modules, it has to keep the function. That's what this flag is made for. > > If your need is to mark a function so that it gets discarded after init or module init, just mark it __init. If it is built in, it will be dropped after init. If it is in a module, it will be dropped after the module is initialised. > >> >>> In addition, I'm not sure you can simply define a probe function as __init. What if someone tries to unbind and rebind the device through sysfs for instance ? >> >> Ouch. I feel stupid now. >> >>> It seems there is a special function called __platform_driver_probe() for registering devices when the probe function is to be in __init, see https://elixir.bootlin.com/linux/latest/source/drivers/base/platform.c#L684 >> >> Yes, but only usable by drivers that won't defer probe, and it removes the bind/unbind attributes from sysfs, >> so it shouldn't be used for non-critical drivers, I think. > > I guess it would make sense for watchdog drivers, we don't expect this kind of driver to be unbinded, do we ? > Except for debugging, where it can be extremely useful to be able to do it. Guenter > Christophe > >> >>> Christophe >>> >>>> >>>> Signed-off-by: Paul Cercueil >>>> --- >>>> >>>> Notes: >>>>      v2: New patch >>>> >>>>   drivers/watchdog/jz4740_wdt.c | 2 +- >>>>   1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/watchdog/jz4740_wdt.c b/drivers/watchdog/jz4740_wdt.c >>>> index 7519d80c5d05..2061788c1939 100644 >>>> --- a/drivers/watchdog/jz4740_wdt.c >>>> +++ b/drivers/watchdog/jz4740_wdt.c >>>> @@ -157,7 +157,7 @@ static const struct of_device_id jz4740_wdt_of_matches[] = { >>>>   MODULE_DEVICE_TABLE(of, jz4740_wdt_of_matches); >>>>   #endif >>>>   -static int jz4740_wdt_probe(struct platform_device *pdev) >>>> +static int __init_or_module jz4740_wdt_probe(struct platform_device *pdev) >>>>   { >>>>       struct device *dev = &pdev->dev; >>>>       struct jz4740_wdt_drvdata *drvdata; >>>> >> >