linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v0 16/42] USB: Check notifier registration return value
       [not found] <20211108101157.15189-1-bp@alien8.de>
@ 2021-11-08 10:11 ` Borislav Petkov
  2021-11-08 14:05   ` Alan Stern
  2021-11-08 10:11 ` [PATCH v0 42/42] notifier: Return an error when callback is already registered Borislav Petkov
  2021-11-08 10:19 ` [PATCH v0 00/42] notifiers: " Borislav Petkov
  2 siblings, 1 reply; 18+ messages in thread
From: Borislav Petkov @ 2021-11-08 10:11 UTC (permalink / raw)
  To: LKML; +Cc: linux-usb

From: Borislav Petkov <bp@suse.de>

Avoid homegrown notifier registration checks.

No functional changes.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: linux-usb@vger.kernel.org
---
 drivers/usb/core/notify.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c
index e6143663778f..80d1bfa61887 100644
--- a/drivers/usb/core/notify.c
+++ b/drivers/usb/core/notify.c
@@ -28,7 +28,8 @@ static BLOCKING_NOTIFIER_HEAD(usb_notifier_list);
  */
 void usb_register_notify(struct notifier_block *nb)
 {
-	blocking_notifier_chain_register(&usb_notifier_list, nb);
+	if (blocking_notifier_chain_register(&usb_notifier_list, nb))
+		pr_warn("USB change notifier already registered\n");
 }
 EXPORT_SYMBOL_GPL(usb_register_notify);
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v0 42/42] notifier: Return an error when callback is already registered
       [not found] <20211108101157.15189-1-bp@alien8.de>
  2021-11-08 10:11 ` [PATCH v0 16/42] USB: Check notifier registration return value Borislav Petkov
@ 2021-11-08 10:11 ` Borislav Petkov
  2021-11-08 14:07   ` Geert Uytterhoeven
  2021-11-08 10:19 ` [PATCH v0 00/42] notifiers: " Borislav Petkov
  2 siblings, 1 reply; 18+ messages in thread
From: Borislav Petkov @ 2021-11-08 10:11 UTC (permalink / raw)
  To: LKML
  Cc: Thomas Gleixner, Arnd Bergmann, Ayush Sawal, Greg Kroah-Hartman,
	Rohit Maheshwari, Steven Rostedt, Vinay Kumar Yadav, alsa-devel,
	bcm-kernel-feedback-list, intel-gfx, intel-gvt-dev, linux-alpha,
	linux-arm-kernel, linux-clk, linux-crypto, linux-edac,
	linux-fbdev, linux-hyperv, linux-iio, linux-leds, linux-mips,
	linux-parisc, linux-pm, linuxppc-dev, linux-remoteproc,
	linux-renesas-soc, linux-s390, linux-scsi, linux-sh,
	linux-staging, linux-tegra, linux-um, linux-usb, linux-xtensa,
	netdev, openipmi-developer, rcu, sparclinux, x86, xen-devel

From: Borislav Petkov <bp@suse.de>

The notifier registration routine doesn't return a proper error value
when a callback has already been registered, leading people to track
whether that registration has happened at the call site:

  https://lore.kernel.org/amd-gfx/20210512013058.6827-1-mukul.joshi@amd.com/

Which is unnecessary.

Return -EEXIST to signal that case so that callers can act accordingly.
Enforce callers to check the return value, leading to loud screaming
during build:

  arch/x86/kernel/cpu/mce/core.c: In function ‘mce_register_decode_chain’:
  arch/x86/kernel/cpu/mce/core.c:167:2: error: ignoring return value of \
   ‘blocking_notifier_chain_register’, declared with attribute warn_unused_result [-Werror=unused-result]
    blocking_notifier_chain_register(&x86_mce_decoder_chain, nb);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Drop the WARN too, while at it.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Ayush Sawal <ayush.sawal@chelsio.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Rohit Maheshwari <rohitm@chelsio.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Vinay Kumar Yadav <vinay.yadav@chelsio.com>
Cc: alsa-devel@alsa-project.org
Cc: bcm-kernel-feedback-list@broadcom.com
Cc: intel-gfx@lists.freedesktop.org
Cc: intel-gvt-dev@lists.freedesktop.org
Cc: linux-alpha@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-clk@vger.kernel.org
Cc: linux-crypto@vger.kernel.org
Cc: linux-edac@vger.kernel.org
Cc: linux-fbdev@vger.kernel.org
Cc: linux-hyperv@vger.kernel.org
Cc: linux-iio@vger.kernel.org
Cc: linux-leds@vger.kernel.org
Cc: linux-mips@vger.kernel.org
Cc: linux-parisc@vger.kernel.org
Cc: linux-pm@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-remoteproc@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org
Cc: linux-s390@vger.kernel.org
Cc: linux-scsi@vger.kernel.org
Cc: linux-sh@vger.kernel.org
Cc: linux-staging@lists.linux.dev
Cc: linux-tegra@vger.kernel.org
Cc: linux-um@lists.infradead.org
Cc: linux-usb@vger.kernel.org
Cc: linux-xtensa@linux-xtensa.org
Cc: netdev@vger.kernel.org
Cc: openipmi-developer@lists.sourceforge.net
Cc: rcu@vger.kernel.org
Cc: sparclinux@vger.kernel.org
Cc: x86@kernel.org
Cc: xen-devel@lists.xenproject.org
---
 include/linux/notifier.h |  8 ++++----
 kernel/notifier.c        | 36 +++++++++++++++++++-----------------
 2 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/include/linux/notifier.h b/include/linux/notifier.h
index 87069b8459af..45cc5a8d0fd8 100644
--- a/include/linux/notifier.h
+++ b/include/linux/notifier.h
@@ -141,13 +141,13 @@ extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
 
 #ifdef __KERNEL__
 
-extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
+extern int __must_check atomic_notifier_chain_register(struct atomic_notifier_head *nh,
 		struct notifier_block *nb);
-extern int blocking_notifier_chain_register(struct blocking_notifier_head *nh,
+extern int __must_check blocking_notifier_chain_register(struct blocking_notifier_head *nh,
 		struct notifier_block *nb);
-extern int raw_notifier_chain_register(struct raw_notifier_head *nh,
+extern int __must_check raw_notifier_chain_register(struct raw_notifier_head *nh,
 		struct notifier_block *nb);
-extern int srcu_notifier_chain_register(struct srcu_notifier_head *nh,
+extern int __must_check srcu_notifier_chain_register(struct srcu_notifier_head *nh,
 		struct notifier_block *nb);
 
 extern int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
diff --git a/kernel/notifier.c b/kernel/notifier.c
index b8251dc0bc0f..451ef3f73ad2 100644
--- a/kernel/notifier.c
+++ b/kernel/notifier.c
@@ -20,13 +20,11 @@ BLOCKING_NOTIFIER_HEAD(reboot_notifier_list);
  */
 
 static int notifier_chain_register(struct notifier_block **nl,
-		struct notifier_block *n)
+				   struct notifier_block *n)
 {
 	while ((*nl) != NULL) {
-		if (unlikely((*nl) == n)) {
-			WARN(1, "double register detected");
-			return 0;
-		}
+		if (unlikely((*nl) == n))
+			return -EEXIST;
 		if (n->priority > (*nl)->priority)
 			break;
 		nl = &((*nl)->next);
@@ -134,10 +132,11 @@ static int notifier_call_chain_robust(struct notifier_block **nl,
  *
  *	Adds a notifier to an atomic notifier chain.
  *
- *	Currently always returns zero.
+ *	Returns 0 on success, %-EEXIST on error.
  */
-int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
-		struct notifier_block *n)
+int __must_check
+atomic_notifier_chain_register(struct atomic_notifier_head *nh,
+			       struct notifier_block *n)
 {
 	unsigned long flags;
 	int ret;
@@ -216,10 +215,11 @@ NOKPROBE_SYMBOL(atomic_notifier_call_chain);
  *	Adds a notifier to a blocking notifier chain.
  *	Must be called in process context.
  *
- *	Currently always returns zero.
+ *	Returns 0 on success, %-EEXIST on error.
  */
-int blocking_notifier_chain_register(struct blocking_notifier_head *nh,
-		struct notifier_block *n)
+int __must_check
+blocking_notifier_chain_register(struct blocking_notifier_head *nh,
+				 struct notifier_block *n)
 {
 	int ret;
 
@@ -335,10 +335,11 @@ EXPORT_SYMBOL_GPL(blocking_notifier_call_chain);
  *	Adds a notifier to a raw notifier chain.
  *	All locking must be provided by the caller.
  *
- *	Currently always returns zero.
+ *	Returns 0 on success, %-EEXIST on error.
  */
-int raw_notifier_chain_register(struct raw_notifier_head *nh,
-		struct notifier_block *n)
+int __must_check
+raw_notifier_chain_register(struct raw_notifier_head *nh,
+			    struct notifier_block *n)
 {
 	return notifier_chain_register(&nh->head, n);
 }
@@ -406,10 +407,11 @@ EXPORT_SYMBOL_GPL(raw_notifier_call_chain);
  *	Adds a notifier to an SRCU notifier chain.
  *	Must be called in process context.
  *
- *	Currently always returns zero.
+ *	Returns 0 on success, %-EEXIST on error.
  */
-int srcu_notifier_chain_register(struct srcu_notifier_head *nh,
-		struct notifier_block *n)
+int __must_check
+srcu_notifier_chain_register(struct srcu_notifier_head *nh,
+			     struct notifier_block *n)
 {
 	int ret;
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v0 00/42] notifiers: Return an error when callback is already registered
       [not found] <20211108101157.15189-1-bp@alien8.de>
  2021-11-08 10:11 ` [PATCH v0 16/42] USB: Check notifier registration return value Borislav Petkov
  2021-11-08 10:11 ` [PATCH v0 42/42] notifier: Return an error when callback is already registered Borislav Petkov
@ 2021-11-08 10:19 ` Borislav Petkov
  2021-11-08 14:17   ` Alan Stern
  2 siblings, 1 reply; 18+ messages in thread
From: Borislav Petkov @ 2021-11-08 10:19 UTC (permalink / raw)
  To: LKML
  Cc: Arnd Bergmann, Ayush Sawal, Greg Kroah-Hartman, Rohit Maheshwari,
	Steven Rostedt, Vinay Kumar Yadav, alsa-devel,
	bcm-kernel-feedback-list, intel-gfx, intel-gvt-dev, linux-alpha,
	linux-arm-kernel, linux-clk, linux-crypto, linux-edac,
	linux-fbdev, linux-hyperv, linux-iio, linux-leds, linux-mips,
	linux-parisc, linux-pm, linuxppc-dev, linux-remoteproc,
	linux-renesas-soc, linux-s390, linux-scsi, linux-sh,
	linux-staging, linux-tegra, linux-um, linux-usb, linux-xtensa,
	netdev, openipmi-developer, rcu, sparclinux, x86, xen-devel

From: Borislav Petkov <bp@suse.de>

Hi all,

this is a huge patchset for something which is really trivial - it
changes the notifier registration routines to return an error value
if a notifier callback is already present on the respective list of
callbacks. For more details scroll to the last patch.

Everything before it is converting the callers to check the return value
of the registration routines and issue a warning, instead of the WARN()
notifier_chain_register() does now.

Before the last patch has been applied, though, that checking is a
NOP which would make the application of those patches trivial - every
maintainer can pick a patch at her/his discretion - only the last one
enables the build warnings and that one will be queued only after the
preceding patches have all been merged so that there are no build
warnings.

Due to the sheer volume of the patches, I have addressed the respective
patch and the last one, which enables the warning, with addressees for
each maintained area so as not to spam people unnecessarily.

If people prefer I carry some through tip, instead, I'll gladly do so -
your call.

And, if you think the warning messages need to be more precise, feel
free to adjust them before committing.

Thanks!

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Ayush Sawal <ayush.sawal@chelsio.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Rohit Maheshwari <rohitm@chelsio.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Vinay Kumar Yadav <vinay.yadav@chelsio.com> 
Cc: alsa-devel@alsa-project.org
Cc: bcm-kernel-feedback-list@broadcom.com
Cc: intel-gfx@lists.freedesktop.org
Cc: intel-gvt-dev@lists.freedesktop.org
Cc: linux-alpha@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-clk@vger.kernel.org
Cc: linux-crypto@vger.kernel.org
Cc: linux-edac@vger.kernel.org
Cc: linux-fbdev@vger.kernel.org
Cc: linux-hyperv@vger.kernel.org
Cc: linux-iio@vger.kernel.org
Cc: linux-leds@vger.kernel.org
Cc: linux-mips@vger.kernel.org
Cc: linux-parisc@vger.kernel.org
Cc: linux-pm@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-remoteproc@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org
Cc: linux-s390@vger.kernel.org
Cc: linux-scsi@vger.kernel.org
Cc: linux-sh@vger.kernel.org
Cc: linux-staging@lists.linux.dev
Cc: linux-tegra@vger.kernel.org
Cc: linux-um@lists.infradead.org
Cc: linux-usb@vger.kernel.org
Cc: linux-xtensa@linux-xtensa.org
Cc: netdev@vger.kernel.org
Cc: openipmi-developer@lists.sourceforge.net
Cc: rcu@vger.kernel.org
Cc: sparclinux@vger.kernel.org
Cc: x86@kernel.org
Cc: xen-devel@lists.xenproject.org

Borislav Petkov (42):
  x86: Check notifier registration return value
  xen/x86: Check notifier registration return value
  impi: Check notifier registration return value
  clk: renesas: Check notifier registration return value
  dca: Check notifier registration return value
  firmware: Check notifier registration return value
  drm/i915: Check notifier registration return value
  Drivers: hv: vmbus: Check notifier registration return value
  iio: proximity: cros_ec: Check notifier registration return value
  leds: trigger: Check notifier registration return value
  misc: Check notifier registration return value
  ethernet: chelsio: Check notifier registration return value
  power: reset: Check notifier registration return value
  remoteproc: Check notifier registration return value
  scsi: target: Check notifier registration return value
  USB: Check notifier registration return value
  drivers: video: Check notifier registration return value
  drivers/xen: Check notifier registration return value
  kernel/hung_task: Check notifier registration return value
  rcu: Check notifier registration return value
  tracing: Check notifier registration return value
  net: fib_notifier: Check notifier registration return value
  ASoC: soc-jack: Check notifier registration return value
  staging: olpc_dcon: Check notifier registration return value
  arch/um: Check notifier registration return value
  alpha: Check notifier registration return value
  bus: brcmstb_gisb: Check notifier registration return value
  soc: bcm: brcmstb: pm: pm-arm: Check notifier registration return
    value
  arm64: Check notifier registration return value
  soc/tegra: Check notifier registration return value
  parisc: Check notifier registration return value
  macintosh/adb: Check notifier registration return value
  mips: Check notifier registration return value
  powerpc: Check notifier registration return value
  sh: Check notifier registration return value
  s390: Check notifier registration return value
  sparc: Check notifier registration return value
  xtensa: Check notifier registration return value
  crypto: ccree - check notifier registration return value
  EDAC/altera: Check notifier registration return value
  power: supply: ab8500: Check notifier registration return value
  notifier: Return an error when callback is already registered

 arch/alpha/kernel/setup.c                     |  5 +--
 arch/arm64/kernel/setup.c                     |  6 ++--
 arch/mips/kernel/relocate.c                   |  6 ++--
 arch/mips/sgi-ip22/ip22-reset.c               |  4 ++-
 arch/mips/sgi-ip32/ip32-reset.c               |  4 ++-
 arch/parisc/kernel/pdc_chassis.c              |  5 +--
 arch/powerpc/kernel/setup-common.c            | 12 ++++---
 arch/s390/kernel/ipl.c                        |  4 ++-
 arch/s390/kvm/kvm-s390.c                      |  7 ++--
 arch/sh/kernel/cpu/sh4a/setup-sh7724.c        | 11 +++---
 arch/sparc/kernel/sstate.c                    |  6 ++--
 arch/um/drivers/mconsole_kern.c               |  6 ++--
 arch/um/kernel/um_arch.c                      |  5 +--
 arch/x86/kernel/cpu/mce/core.c                |  3 +-
 arch/x86/kernel/cpu/mce/dev-mcelog.c          |  3 +-
 arch/x86/kernel/setup.c                       |  7 ++--
 arch/x86/xen/enlighten.c                      |  4 ++-
 arch/xtensa/platforms/iss/setup.c             |  3 +-
 drivers/bus/brcmstb_gisb.c                    |  6 ++--
 drivers/char/ipmi/ipmi_msghandler.c           |  3 +-
 drivers/clk/renesas/clk-div6.c                |  4 ++-
 drivers/clk/renesas/rcar-cpg-lib.c            |  4 ++-
 drivers/crypto/ccree/cc_fips.c                |  4 ++-
 drivers/dca/dca-core.c                        |  3 +-
 drivers/edac/altera_edac.c                    |  6 ++--
 drivers/firmware/arm_scmi/notify.c            |  3 +-
 drivers/firmware/google/gsmi.c                |  6 ++--
 drivers/gpu/drm/i915/gvt/scheduler.c          |  6 ++--
 drivers/hv/vmbus_drv.c                        |  4 +--
 .../iio/proximity/cros_ec_mkbp_proximity.c    |  3 +-
 drivers/leds/trigger/ledtrig-activity.c       |  6 ++--
 drivers/leds/trigger/ledtrig-heartbeat.c      |  6 ++--
 drivers/leds/trigger/ledtrig-panic.c          |  4 +--
 drivers/macintosh/adbhid.c                    |  4 +--
 drivers/misc/ibmasm/heartbeat.c               |  3 +-
 drivers/misc/pvpanic/pvpanic.c                |  3 +-
 .../chelsio/inline_crypto/chtls/chtls_main.c  |  5 ++-
 drivers/parisc/power.c                        |  5 +--
 drivers/power/reset/ltc2952-poweroff.c        |  6 ++--
 drivers/power/supply/ab8500_charger.c         |  8 ++---
 drivers/remoteproc/qcom_common.c              |  3 +-
 drivers/remoteproc/qcom_sysmon.c              |  4 ++-
 drivers/remoteproc/remoteproc_core.c          |  4 ++-
 drivers/s390/char/con3215.c                   |  5 ++-
 drivers/s390/char/con3270.c                   |  5 ++-
 drivers/s390/char/sclp_con.c                  |  4 ++-
 drivers/s390/char/sclp_vt220.c                |  4 ++-
 drivers/s390/char/zcore.c                     |  4 ++-
 drivers/soc/bcm/brcmstb/pm/pm-arm.c           |  5 +--
 drivers/soc/tegra/ari-tegra186.c              |  7 ++--
 drivers/staging/olpc_dcon/olpc_dcon.c         |  4 ++-
 drivers/target/tcm_fc/tfc_conf.c              |  4 ++-
 drivers/usb/core/notify.c                     |  3 +-
 drivers/video/console/dummycon.c              |  3 +-
 drivers/video/fbdev/hyperv_fb.c               |  5 +--
 drivers/xen/manage.c                          |  3 +-
 drivers/xen/xenbus/xenbus_probe.c             |  8 +++--
 include/linux/notifier.h                      |  8 ++---
 kernel/hung_task.c                            |  3 +-
 kernel/notifier.c                             | 36 ++++++++++---------
 kernel/rcu/tree_stall.h                       |  4 ++-
 kernel/trace/trace.c                          |  4 +--
 net/core/fib_notifier.c                       |  4 ++-
 sound/soc/soc-jack.c                          |  3 +-
 64 files changed, 222 insertions(+), 118 deletions(-)

-- 
2.29.2


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 16/42] USB: Check notifier registration return value
  2021-11-08 10:11 ` [PATCH v0 16/42] USB: Check notifier registration return value Borislav Petkov
@ 2021-11-08 14:05   ` Alan Stern
  2021-11-08 14:09     ` Borislav Petkov
  0 siblings, 1 reply; 18+ messages in thread
From: Alan Stern @ 2021-11-08 14:05 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: LKML, linux-usb

On Mon, Nov 08, 2021 at 11:11:31AM +0100, Borislav Petkov wrote:
> From: Borislav Petkov <bp@suse.de>
> 
> Avoid homegrown notifier registration checks.

This is a rather misleading description.  The patch does exactly the 
opposite: It _adds_ a homegrown notifier registration check.  (Homegrown 
in the sense that the check is made by the individual caller rather than 
being centralized in the routine being called.)

Alan Stern

> No functional changes.
> 
> Signed-off-by: Borislav Petkov <bp@suse.de>
> Cc: linux-usb@vger.kernel.org
> ---
>  drivers/usb/core/notify.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c
> index e6143663778f..80d1bfa61887 100644
> --- a/drivers/usb/core/notify.c
> +++ b/drivers/usb/core/notify.c
> @@ -28,7 +28,8 @@ static BLOCKING_NOTIFIER_HEAD(usb_notifier_list);
>   */
>  void usb_register_notify(struct notifier_block *nb)
>  {
> -	blocking_notifier_chain_register(&usb_notifier_list, nb);
> +	if (blocking_notifier_chain_register(&usb_notifier_list, nb))
> +		pr_warn("USB change notifier already registered\n");
>  }
>  EXPORT_SYMBOL_GPL(usb_register_notify);
>  
> -- 
> 2.29.2
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 42/42] notifier: Return an error when callback is already registered
  2021-11-08 10:11 ` [PATCH v0 42/42] notifier: Return an error when callback is already registered Borislav Petkov
@ 2021-11-08 14:07   ` Geert Uytterhoeven
  2021-11-08 14:21     ` Borislav Petkov
  0 siblings, 1 reply; 18+ messages in thread
From: Geert Uytterhoeven @ 2021-11-08 14:07 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: LKML, Thomas Gleixner, Arnd Bergmann, Ayush Sawal,
	Greg Kroah-Hartman, Rohit Maheshwari, Steven Rostedt,
	Vinay Kumar Yadav, ALSA Development Mailing List,
	bcm-kernel-feedback-list, Intel Graphics Development,
	intel-gvt-dev, alpha, Linux ARM, linux-clk,
	Linux Crypto Mailing List, linux-edac,
	Linux Fbdev development list, linux-hyperv, linux-iio,
	linux-leds, open list:BROADCOM NVRAM DRIVER, Parisc List,
	Linux PM list, linuxppc-dev,
	open list:REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM, Linux-Renesas,
	linux-s390, scsi, Linux-sh list, linux-staging, linux-tegra,
	linux-um, USB list, open list:TENSILICA XTENSA PORT (xtensa),
	netdev, openipmi-developer, rcu, sparclinux,
	the arch/x86 maintainers, xen-devel

Hi Borislav,

On Mon, Nov 8, 2021 at 11:13 AM Borislav Petkov <bp@alien8.de> wrote:
> From: Borislav Petkov <bp@suse.de>
>
> The notifier registration routine doesn't return a proper error value
> when a callback has already been registered, leading people to track
> whether that registration has happened at the call site:
>
>   https://lore.kernel.org/amd-gfx/20210512013058.6827-1-mukul.joshi@amd.com/
>
> Which is unnecessary.
>
> Return -EEXIST to signal that case so that callers can act accordingly.
> Enforce callers to check the return value, leading to loud screaming
> during build:
>
>   arch/x86/kernel/cpu/mce/core.c: In function ‘mce_register_decode_chain’:
>   arch/x86/kernel/cpu/mce/core.c:167:2: error: ignoring return value of \
>    ‘blocking_notifier_chain_register’, declared with attribute warn_unused_result [-Werror=unused-result]
>     blocking_notifier_chain_register(&x86_mce_decoder_chain, nb);
>   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Drop the WARN too, while at it.
>
> Suggested-by: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Borislav Petkov <bp@suse.de>

Thanks for your patch!

> --- a/include/linux/notifier.h
> +++ b/include/linux/notifier.h
> @@ -141,13 +141,13 @@ extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
>
>  #ifdef __KERNEL__
>
> -extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
> +extern int __must_check atomic_notifier_chain_register(struct atomic_notifier_head *nh,
>                 struct notifier_block *nb);
> -extern int blocking_notifier_chain_register(struct blocking_notifier_head *nh,
> +extern int __must_check blocking_notifier_chain_register(struct blocking_notifier_head *nh,
>                 struct notifier_block *nb);
> -extern int raw_notifier_chain_register(struct raw_notifier_head *nh,
> +extern int __must_check raw_notifier_chain_register(struct raw_notifier_head *nh,
>                 struct notifier_block *nb);
> -extern int srcu_notifier_chain_register(struct srcu_notifier_head *nh,
> +extern int __must_check srcu_notifier_chain_register(struct srcu_notifier_head *nh,
>                 struct notifier_block *nb);

I think the addition of __must_check is overkill, leading to the
addition of useless error checks and message printing.  Many callers
call this where it cannot fail, and where nothing can be done in the
very unlikely event that the call would ever start to fail.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 16/42] USB: Check notifier registration return value
  2021-11-08 14:05   ` Alan Stern
@ 2021-11-08 14:09     ` Borislav Petkov
  0 siblings, 0 replies; 18+ messages in thread
From: Borislav Petkov @ 2021-11-08 14:09 UTC (permalink / raw)
  To: Alan Stern; +Cc: LKML, linux-usb

On Mon, Nov 08, 2021 at 09:05:53AM -0500, Alan Stern wrote:
> This is a rather misleading description.  The patch does exactly the 
> opposite: It _adds_ a homegrown notifier registration check.  (Homegrown 
> in the sense that the check is made by the individual caller rather than 
> being centralized in the routine being called.)

See the 0th message - there is a link to another example of what I mean
with "homegrown" but I see your point.

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 00/42] notifiers: Return an error when callback is already registered
  2021-11-08 10:19 ` [PATCH v0 00/42] notifiers: " Borislav Petkov
@ 2021-11-08 14:17   ` Alan Stern
  2021-11-08 14:24     ` Borislav Petkov
  0 siblings, 1 reply; 18+ messages in thread
From: Alan Stern @ 2021-11-08 14:17 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: LKML, Arnd Bergmann, Ayush Sawal, Greg Kroah-Hartman,
	Rohit Maheshwari, Steven Rostedt, Vinay Kumar Yadav, alsa-devel,
	bcm-kernel-feedback-list, intel-gfx, intel-gvt-dev, linux-alpha,
	linux-arm-kernel, linux-clk, linux-crypto, linux-edac,
	linux-fbdev, linux-hyperv, linux-iio, linux-leds, linux-mips,
	linux-parisc, linux-pm, linuxppc-dev, linux-remoteproc,
	linux-renesas-soc, linux-s390, linux-scsi, linux-sh,
	linux-staging, linux-tegra, linux-um, linux-usb, linux-xtensa,
	netdev, openipmi-developer, rcu, sparclinux, x86, xen-devel

On Mon, Nov 08, 2021 at 11:19:24AM +0100, Borislav Petkov wrote:
> From: Borislav Petkov <bp@suse.de>
> 
> Hi all,
> 
> this is a huge patchset for something which is really trivial - it
> changes the notifier registration routines to return an error value
> if a notifier callback is already present on the respective list of
> callbacks. For more details scroll to the last patch.
> 
> Everything before it is converting the callers to check the return value
> of the registration routines and issue a warning, instead of the WARN()
> notifier_chain_register() does now.

What reason is there for moving the check into the callers?  It seems 
like pointless churn.  Why not add the error return code, change the 
WARN to pr_warn, and leave the callers as they are?  Wouldn't that end 
up having exactly the same effect?

For that matter, what sort of remedial action can a caller take if the 
return code is -EEXIST?  Is there any point in forcing callers to check 
the return code if they can't do anything about it?

> Before the last patch has been applied, though, that checking is a
> NOP which would make the application of those patches trivial - every
> maintainer can pick a patch at her/his discretion - only the last one
> enables the build warnings and that one will be queued only after the
> preceding patches have all been merged so that there are no build
> warnings.

Why should there be _any_ build warnings?  The real problem occurs when 
a notifier callback is added twice, not when a caller fails to check the 
return code.  Double-registration is not the sort of thing that can be 
detected at build time.

Alan Stern

> Due to the sheer volume of the patches, I have addressed the respective
> patch and the last one, which enables the warning, with addressees for
> each maintained area so as not to spam people unnecessarily.
> 
> If people prefer I carry some through tip, instead, I'll gladly do so -
> your call.
> 
> And, if you think the warning messages need to be more precise, feel
> free to adjust them before committing.
> 
> Thanks!

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 42/42] notifier: Return an error when callback is already registered
  2021-11-08 14:07   ` Geert Uytterhoeven
@ 2021-11-08 14:21     ` Borislav Petkov
  2021-11-08 15:25       ` Geert Uytterhoeven
  0 siblings, 1 reply; 18+ messages in thread
From: Borislav Petkov @ 2021-11-08 14:21 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: LKML, Thomas Gleixner, Arnd Bergmann, Ayush Sawal,
	Greg Kroah-Hartman, Rohit Maheshwari, Steven Rostedt,
	Vinay Kumar Yadav, ALSA Development Mailing List,
	bcm-kernel-feedback-list, Intel Graphics Development,
	intel-gvt-dev, alpha, Linux ARM, linux-clk,
	Linux Crypto Mailing List, linux-edac,
	Linux Fbdev development list, linux-hyperv, linux-iio,
	linux-leds, open list:BROADCOM NVRAM DRIVER, Parisc List,
	Linux PM list, linuxppc-dev,
	open list:REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM, Linux-Renesas,
	linux-s390, scsi, Linux-sh list, linux-staging, linux-tegra,
	linux-um, USB list, open list:TENSILICA XTENSA PORT (xtensa),
	netdev, openipmi-developer, rcu, sparclinux,
	the arch/x86 maintainers, xen-devel

On Mon, Nov 08, 2021 at 03:07:03PM +0100, Geert Uytterhoeven wrote:
> I think the addition of __must_check is overkill, leading to the
> addition of useless error checks and message printing.

See the WARN in notifier_chain_register() - it will already do "message
printing".

> Many callers call this where it cannot fail, and where nothing can
> be done in the very unlikely event that the call would ever start to
> fail.

This is an attempt to remove this WARN() hack in
notifier_chain_register() and have the function return a proper error
value instead of this "Currently always returns zero." which is bad
design.

Some of the registration functions around the tree check that retval and
some don't. So if "it cannot fail" those registration either should not
return a value or callers should check that return value - what we have
now doesn't make a whole lot of sense.

Oh, and then fixing this should avoid stuff like:

+	if (notifier_registered == false) {
+		mce_register_decode_chain(&amdgpu_bad_page_nb);
+		notifier_registered = true;
+	}

from propagating in the code.

The other idea I have is to add another indirection in
notifier_chain_register() which will check the *proper* return value of
a lower level __notifier_chain_register() and then issue that warning.
That would definitely avoid touch so many call sites.

Bottom line is: what we have now needs cleaning up.

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 00/42] notifiers: Return an error when callback is already registered
  2021-11-08 14:17   ` Alan Stern
@ 2021-11-08 14:24     ` Borislav Petkov
  2021-11-08 14:35       ` Borislav Petkov
  0 siblings, 1 reply; 18+ messages in thread
From: Borislav Petkov @ 2021-11-08 14:24 UTC (permalink / raw)
  To: Alan Stern
  Cc: LKML, Arnd Bergmann, Ayush Sawal, Greg Kroah-Hartman,
	Rohit Maheshwari, Steven Rostedt, Vinay Kumar Yadav, alsa-devel,
	bcm-kernel-feedback-list, intel-gfx, intel-gvt-dev, linux-alpha,
	linux-arm-kernel, linux-clk, linux-crypto, linux-edac,
	linux-fbdev, linux-hyperv, linux-iio, linux-leds, linux-mips,
	linux-parisc, linux-pm, linuxppc-dev, linux-remoteproc,
	linux-renesas-soc, linux-s390, linux-scsi, linux-sh,
	linux-staging, linux-tegra, linux-um, linux-usb, linux-xtensa,
	netdev, openipmi-developer, rcu, sparclinux, x86, xen-devel

On Mon, Nov 08, 2021 at 09:17:03AM -0500, Alan Stern wrote:
> What reason is there for moving the check into the callers?  It seems 
> like pointless churn.  Why not add the error return code, change the 
> WARN to pr_warn, and leave the callers as they are?  Wouldn't that end 
> up having exactly the same effect?
> 
> For that matter, what sort of remedial action can a caller take if the 
> return code is -EEXIST?  Is there any point in forcing callers to check 
> the return code if they can't do anything about it?

See my reply to Geert from just now:

https://lore.kernel.org/r/YYkyUEqcsOwQMb1S@zn.tnic

I guess I can add another indirection to notifier_chain_register() and
avoid touching all the call sites.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 00/42] notifiers: Return an error when callback is already registered
  2021-11-08 14:24     ` Borislav Petkov
@ 2021-11-08 14:35       ` Borislav Petkov
  2021-11-08 16:23         ` Steven Rostedt
  0 siblings, 1 reply; 18+ messages in thread
From: Borislav Petkov @ 2021-11-08 14:35 UTC (permalink / raw)
  To: Alan Stern, Geert Uytterhoeven
  Cc: LKML, Arnd Bergmann, Ayush Sawal, Greg Kroah-Hartman,
	Rohit Maheshwari, Steven Rostedt, Vinay Kumar Yadav, alsa-devel,
	bcm-kernel-feedback-list, intel-gfx, intel-gvt-dev, linux-alpha,
	linux-arm-kernel, linux-clk, linux-crypto, linux-edac,
	linux-fbdev, linux-hyperv, linux-iio, linux-leds, linux-mips,
	linux-parisc, linux-pm, linuxppc-dev, linux-remoteproc,
	linux-renesas-soc, linux-s390, linux-scsi, linux-sh,
	linux-staging, linux-tegra, linux-um, linux-usb, linux-xtensa,
	netdev, openipmi-developer, rcu, sparclinux, x86, xen-devel

On Mon, Nov 08, 2021 at 03:24:39PM +0100, Borislav Petkov wrote:
> I guess I can add another indirection to notifier_chain_register() and
> avoid touching all the call sites.

IOW, something like this below.

This way I won't have to touch all the callsites and the registration
routines would still return a proper value instead of returning 0
unconditionally.

---
diff --git a/kernel/notifier.c b/kernel/notifier.c
index b8251dc0bc0f..04f08b2ef17f 100644
--- a/kernel/notifier.c
+++ b/kernel/notifier.c
@@ -19,14 +19,12 @@ BLOCKING_NOTIFIER_HEAD(reboot_notifier_list);
  *	are layered on top of these, with appropriate locking added.
  */
 
-static int notifier_chain_register(struct notifier_block **nl,
-		struct notifier_block *n)
+static int __notifier_chain_register(struct notifier_block **nl,
+				     struct notifier_block *n)
 {
 	while ((*nl) != NULL) {
-		if (unlikely((*nl) == n)) {
-			WARN(1, "double register detected");
-			return 0;
-		}
+		if (unlikely((*nl) == n))
+			return -EEXIST;
 		if (n->priority > (*nl)->priority)
 			break;
 		nl = &((*nl)->next);
@@ -36,6 +34,18 @@ static int notifier_chain_register(struct notifier_block **nl,
 	return 0;
 }
 
+static int notifier_chain_register(struct notifier_block **nl,
+				   struct notifier_block *n)
+{
+	int ret = __notifier_chain_register(nl, n);
+
+	if (ret == -EEXIST)
+		WARN(1, "double register of notifier callback %ps detected",
+			n->notifier_call);
+
+	return ret;
+}
+
 static int notifier_chain_unregister(struct notifier_block **nl,
 		struct notifier_block *n)
 {


-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 42/42] notifier: Return an error when callback is already registered
  2021-11-08 14:21     ` Borislav Petkov
@ 2021-11-08 15:25       ` Geert Uytterhoeven
  2021-11-08 15:58         ` Borislav Petkov
  0 siblings, 1 reply; 18+ messages in thread
From: Geert Uytterhoeven @ 2021-11-08 15:25 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: LKML, Thomas Gleixner, Arnd Bergmann, Ayush Sawal,
	Greg Kroah-Hartman, Rohit Maheshwari, Steven Rostedt,
	Vinay Kumar Yadav, ALSA Development Mailing List,
	bcm-kernel-feedback-list, Intel Graphics Development,
	intel-gvt-dev, alpha, Linux ARM, linux-clk,
	Linux Crypto Mailing List, linux-edac,
	Linux Fbdev development list, linux-hyperv, linux-iio,
	linux-leds, open list:BROADCOM NVRAM DRIVER, Parisc List,
	Linux PM list, linuxppc-dev,
	open list:REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM, Linux-Renesas,
	linux-s390, scsi, Linux-sh list, linux-staging, linux-tegra,
	linux-um, USB list, open list:TENSILICA XTENSA PORT (xtensa),
	netdev, openipmi-developer, rcu, sparclinux,
	the arch/x86 maintainers, xen-devel

Hi Borislav,

On Mon, Nov 8, 2021 at 3:21 PM Borislav Petkov <bp@alien8.de> wrote:
> On Mon, Nov 08, 2021 at 03:07:03PM +0100, Geert Uytterhoeven wrote:
> > I think the addition of __must_check is overkill, leading to the
> > addition of useless error checks and message printing.
>
> See the WARN in notifier_chain_register() - it will already do "message
> printing".

I mean the addition of useless error checks and message printing _to
the callers_.

> > Many callers call this where it cannot fail, and where nothing can
> > be done in the very unlikely event that the call would ever start to
> > fail.
>
> This is an attempt to remove this WARN() hack in
> notifier_chain_register() and have the function return a proper error
> value instead of this "Currently always returns zero." which is bad
> design.
>
> Some of the registration functions around the tree check that retval and
> some don't. So if "it cannot fail" those registration either should not
> return a value or callers should check that return value - what we have
> now doesn't make a whole lot of sense.

With __must_check callers are required to check, even if they know
it cannot fail.

> Oh, and then fixing this should avoid stuff like:
>
> +       if (notifier_registered == false) {
> +               mce_register_decode_chain(&amdgpu_bad_page_nb);
> +               notifier_registered = true;
> +       }
>
> from propagating in the code.

That's unrelated to the addition of __must_check.

I'm not against returning proper errors codes.  I'm against forcing
callers to check things that cannot fail and to add individual error
printing to each and every caller.

Note that in other areas, we are moving in the other
direction, to a centralized printing of error messages,
cfr. e.g. commit 7723f4c5ecdb8d83 ("driver core: platform: Add an
error message to platform_get_irq*()").

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 42/42] notifier: Return an error when callback is already registered
  2021-11-08 15:25       ` Geert Uytterhoeven
@ 2021-11-08 15:58         ` Borislav Petkov
  2021-11-08 16:12           ` Geert Uytterhoeven
  0 siblings, 1 reply; 18+ messages in thread
From: Borislav Petkov @ 2021-11-08 15:58 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: LKML, Thomas Gleixner, Arnd Bergmann, Ayush Sawal,
	Greg Kroah-Hartman, Rohit Maheshwari, Steven Rostedt,
	Vinay Kumar Yadav, ALSA Development Mailing List,
	bcm-kernel-feedback-list, Intel Graphics Development,
	intel-gvt-dev, alpha, Linux ARM, linux-clk,
	Linux Crypto Mailing List, linux-edac,
	Linux Fbdev development list, linux-hyperv, linux-iio,
	linux-leds, open list:BROADCOM NVRAM DRIVER, Parisc List,
	Linux PM list, linuxppc-dev,
	open list:REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM, Linux-Renesas,
	linux-s390, scsi, Linux-sh list, linux-staging, linux-tegra,
	linux-um, USB list, open list:TENSILICA XTENSA PORT (xtensa),
	netdev, openipmi-developer, rcu, sparclinux,
	the arch/x86 maintainers, xen-devel

On Mon, Nov 08, 2021 at 04:25:47PM +0100, Geert Uytterhoeven wrote:
> I'm not against returning proper errors codes.  I'm against forcing
> callers to check things that cannot fail and to add individual error
> printing to each and every caller.

If you're against checking things at the callers, then the registration
function should be void. IOW, those APIs are not optimally designed atm.

> Note that in other areas, we are moving in the other direction,
> to a centralized printing of error messages, cfr. e.g. commit
> 7723f4c5ecdb8d83 ("driver core: platform: Add an error message to
> platform_get_irq*()").

Yes, thus my other idea to add a lower level __notifier_chain_register()
to do the checking.

I'll see if I can convert those notifier registration functions to
return void, in the process. But let's see what the others think first.

Thanks for taking the time.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 42/42] notifier: Return an error when callback is already registered
  2021-11-08 15:58         ` Borislav Petkov
@ 2021-11-08 16:12           ` Geert Uytterhoeven
  2021-11-08 16:21             ` Borislav Petkov
  0 siblings, 1 reply; 18+ messages in thread
From: Geert Uytterhoeven @ 2021-11-08 16:12 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: LKML, Thomas Gleixner, Arnd Bergmann, Ayush Sawal,
	Greg Kroah-Hartman, Rohit Maheshwari, Steven Rostedt,
	Vinay Kumar Yadav, ALSA Development Mailing List,
	bcm-kernel-feedback-list, Intel Graphics Development,
	intel-gvt-dev, alpha, Linux ARM, linux-clk,
	Linux Crypto Mailing List, linux-edac,
	Linux Fbdev development list, linux-hyperv, linux-iio,
	linux-leds, open list:BROADCOM NVRAM DRIVER, Parisc List,
	Linux PM list, linuxppc-dev,
	open list:REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM, Linux-Renesas,
	linux-s390, scsi, Linux-sh list, linux-staging, linux-tegra,
	linux-um, USB list, open list:TENSILICA XTENSA PORT (xtensa),
	netdev, openipmi-developer, rcu, sparclinux,
	the arch/x86 maintainers, xen-devel

Hi Borislav,

On Mon, Nov 8, 2021 at 4:59 PM Borislav Petkov <bp@alien8.de> wrote:
> On Mon, Nov 08, 2021 at 04:25:47PM +0100, Geert Uytterhoeven wrote:
> > I'm not against returning proper errors codes.  I'm against forcing
> > callers to check things that cannot fail and to add individual error
> > printing to each and every caller.
>
> If you're against checking things at the callers, then the registration
> function should be void. IOW, those APIs are not optimally designed atm.

Returning void is the other extreme ;-)

There are 3 levels (ignoring BUG_ON()/panic () inside the callee):
  1. Return void: no one can check success or failure,
  2. Return an error code: up to the caller to decide,
  3. Return a __must_check error code: every caller must check.

I'm in favor of 2, as there are several places where it cannot fail.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 42/42] notifier: Return an error when callback is already registered
  2021-11-08 16:12           ` Geert Uytterhoeven
@ 2021-11-08 16:21             ` Borislav Petkov
  2021-11-08 20:59               ` Alan Stern
  0 siblings, 1 reply; 18+ messages in thread
From: Borislav Petkov @ 2021-11-08 16:21 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: LKML, Thomas Gleixner, Arnd Bergmann, Ayush Sawal,
	Greg Kroah-Hartman, Rohit Maheshwari, Steven Rostedt,
	Vinay Kumar Yadav, ALSA Development Mailing List,
	bcm-kernel-feedback-list, Intel Graphics Development,
	intel-gvt-dev, alpha, Linux ARM, linux-clk,
	Linux Crypto Mailing List, linux-edac,
	Linux Fbdev development list, linux-hyperv, linux-iio,
	linux-leds, open list:BROADCOM NVRAM DRIVER, Parisc List,
	Linux PM list, linuxppc-dev,
	open list:REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM, Linux-Renesas,
	linux-s390, scsi, Linux-sh list, linux-staging, linux-tegra,
	linux-um, USB list, open list:TENSILICA XTENSA PORT (xtensa),
	netdev, openipmi-developer, rcu, sparclinux,
	the arch/x86 maintainers, xen-devel

On Mon, Nov 08, 2021 at 05:12:16PM +0100, Geert Uytterhoeven wrote:
> Returning void is the other extreme ;-)
> 
> There are 3 levels (ignoring BUG_ON()/panic () inside the callee):
>   1. Return void: no one can check success or failure,
>   2. Return an error code: up to the caller to decide,
>   3. Return a __must_check error code: every caller must check.
> 
> I'm in favor of 2, as there are several places where it cannot fail.

Makes sense to me. I'll do that in the next iteration.

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 00/42] notifiers: Return an error when callback is already registered
  2021-11-08 14:35       ` Borislav Petkov
@ 2021-11-08 16:23         ` Steven Rostedt
  2021-11-08 16:29           ` Borislav Petkov
  0 siblings, 1 reply; 18+ messages in thread
From: Steven Rostedt @ 2021-11-08 16:23 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Alan Stern, Geert Uytterhoeven, LKML, Arnd Bergmann, Ayush Sawal,
	Greg Kroah-Hartman, Rohit Maheshwari, Vinay Kumar Yadav,
	alsa-devel, bcm-kernel-feedback-list, intel-gfx, intel-gvt-dev,
	linux-alpha, linux-arm-kernel, linux-clk, linux-crypto,
	linux-edac, linux-fbdev, linux-hyperv, linux-iio, linux-leds,
	linux-mips, linux-parisc, linux-pm, linuxppc-dev,
	linux-remoteproc, linux-renesas-soc, linux-s390, linux-scsi,
	linux-sh, linux-staging, linux-tegra, linux-um, linux-usb,
	linux-xtensa, netdev, openipmi-developer, rcu, sparclinux, x86,
	xen-devel

On Mon, 8 Nov 2021 15:35:50 +0100
Borislav Petkov <bp@alien8.de> wrote:

> On Mon, Nov 08, 2021 at 03:24:39PM +0100, Borislav Petkov wrote:
> > I guess I can add another indirection to notifier_chain_register() and
> > avoid touching all the call sites.  
> 
> IOW, something like this below.
> 
> This way I won't have to touch all the callsites and the registration
> routines would still return a proper value instead of returning 0
> unconditionally.

I prefer this method.

Question, how often does this warning trigger? Is it common to see in
development?

-- Steve

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 00/42] notifiers: Return an error when callback is already registered
  2021-11-08 16:23         ` Steven Rostedt
@ 2021-11-08 16:29           ` Borislav Petkov
  0 siblings, 0 replies; 18+ messages in thread
From: Borislav Petkov @ 2021-11-08 16:29 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Alan Stern, Geert Uytterhoeven, LKML, Arnd Bergmann, Ayush Sawal,
	Greg Kroah-Hartman, Rohit Maheshwari, Vinay Kumar Yadav,
	alsa-devel, bcm-kernel-feedback-list, intel-gfx, intel-gvt-dev,
	linux-alpha, linux-arm-kernel, linux-clk, linux-crypto,
	linux-edac, linux-fbdev, linux-hyperv, linux-iio, linux-leds,
	linux-mips, linux-parisc, linux-pm, linuxppc-dev,
	linux-remoteproc, linux-renesas-soc, linux-s390, linux-scsi,
	linux-sh, linux-staging, linux-tegra, linux-um, linux-usb,
	linux-xtensa, netdev, openipmi-developer, rcu, sparclinux, x86,
	xen-devel

On Mon, Nov 08, 2021 at 11:23:13AM -0500, Steven Rostedt wrote:
> Question, how often does this warning trigger? Is it common to see in
> development?

Yeah, haven't seen it myself yet.

But we hashed it out over IRC. :-)

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 42/42] notifier: Return an error when callback is already registered
  2021-11-08 16:21             ` Borislav Petkov
@ 2021-11-08 20:59               ` Alan Stern
  2021-11-08 21:18                 ` Borislav Petkov
  0 siblings, 1 reply; 18+ messages in thread
From: Alan Stern @ 2021-11-08 20:59 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Geert Uytterhoeven, LKML, Thomas Gleixner, Arnd Bergmann,
	Ayush Sawal, Greg Kroah-Hartman, Rohit Maheshwari,
	Steven Rostedt, Vinay Kumar Yadav, ALSA Development Mailing List,
	bcm-kernel-feedback-list, Intel Graphics Development,
	intel-gvt-dev, alpha, Linux ARM, linux-clk,
	Linux Crypto Mailing List, linux-edac,
	Linux Fbdev development list, linux-hyperv, linux-iio,
	linux-leds, open list:BROADCOM NVRAM DRIVER, Parisc List,
	Linux PM list, linuxppc-dev,
	open list:REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM, Linux-Renesas,
	linux-s390, scsi, Linux-sh list, linux-staging, linux-tegra,
	linux-um, USB list, open list:TENSILICA XTENSA PORT (xtensa),
	netdev, openipmi-developer, rcu, sparclinux,
	the arch/x86 maintainers, xen-devel

On Mon, Nov 08, 2021 at 05:21:45PM +0100, Borislav Petkov wrote:
> On Mon, Nov 08, 2021 at 05:12:16PM +0100, Geert Uytterhoeven wrote:
> > Returning void is the other extreme ;-)
> > 
> > There are 3 levels (ignoring BUG_ON()/panic () inside the callee):
> >   1. Return void: no one can check success or failure,
> >   2. Return an error code: up to the caller to decide,
> >   3. Return a __must_check error code: every caller must check.
> > 
> > I'm in favor of 2, as there are several places where it cannot fail.
> 
> Makes sense to me. I'll do that in the next iteration.

Is there really any reason for returning an error code?  For example, is 
it anticipated that at some point in the future these registration calls 
might fail?

Currently, the only reason for failing to register a notifier callback 
is because the callback is already registered.  In a sense this isn't 
even an actual failure -- after the registration returns the callback 
_will_ still be registered.

So if the call can never really fail, why bother with a return code?  
Especially since the caller can't do anything with such a code value.

Given the current state of affairs, I vote in favor of 1 (plus a WARN or 
something similar to generate a stack dump in the callee, since double 
registration really is a bug).

Alan Stern

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v0 42/42] notifier: Return an error when callback is already registered
  2021-11-08 20:59               ` Alan Stern
@ 2021-11-08 21:18                 ` Borislav Petkov
  0 siblings, 0 replies; 18+ messages in thread
From: Borislav Petkov @ 2021-11-08 21:18 UTC (permalink / raw)
  To: Alan Stern
  Cc: Geert Uytterhoeven, LKML, Thomas Gleixner, Arnd Bergmann,
	Ayush Sawal, Greg Kroah-Hartman, Rohit Maheshwari,
	Steven Rostedt, Vinay Kumar Yadav, ALSA Development Mailing List,
	bcm-kernel-feedback-list, Intel Graphics Development,
	intel-gvt-dev, alpha, Linux ARM, linux-clk,
	Linux Crypto Mailing List, linux-edac,
	Linux Fbdev development list, linux-hyperv, linux-iio,
	linux-leds, open list:BROADCOM NVRAM DRIVER, Parisc List,
	Linux PM list, linuxppc-dev,
	open list:REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM, Linux-Renesas,
	linux-s390, scsi, Linux-sh list, linux-staging, linux-tegra,
	linux-um, USB list, open list:TENSILICA XTENSA PORT (xtensa),
	netdev, openipmi-developer, rcu, sparclinux,
	the arch/x86 maintainers, xen-devel

On Mon, Nov 08, 2021 at 03:59:26PM -0500, Alan Stern wrote:
> Is there really any reason for returning an error code?  For example, is 
> it anticipated that at some point in the future these registration calls 
> might fail?
> 
> Currently, the only reason for failing...

Right, I believe with not making it return void we're leaving the door
open for some, *hypothetical* future return values if we decide we need
to return them too, at some point.

Yes, I can't think of another fact to state besides that the callback
was already registered or return success but who knows what we wanna do
in the future...

And so if we change them all to void now, I think it'll be a lot more
churn to switch back to returning a non-void value and having the
callers who choose to handle that value, do so again.

So, long story short, keeping the retval - albeit not very useful right
now - is probably easier.

I hope I'm making some sense here.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-11-08 21:19 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20211108101157.15189-1-bp@alien8.de>
2021-11-08 10:11 ` [PATCH v0 16/42] USB: Check notifier registration return value Borislav Petkov
2021-11-08 14:05   ` Alan Stern
2021-11-08 14:09     ` Borislav Petkov
2021-11-08 10:11 ` [PATCH v0 42/42] notifier: Return an error when callback is already registered Borislav Petkov
2021-11-08 14:07   ` Geert Uytterhoeven
2021-11-08 14:21     ` Borislav Petkov
2021-11-08 15:25       ` Geert Uytterhoeven
2021-11-08 15:58         ` Borislav Petkov
2021-11-08 16:12           ` Geert Uytterhoeven
2021-11-08 16:21             ` Borislav Petkov
2021-11-08 20:59               ` Alan Stern
2021-11-08 21:18                 ` Borislav Petkov
2021-11-08 10:19 ` [PATCH v0 00/42] notifiers: " Borislav Petkov
2021-11-08 14:17   ` Alan Stern
2021-11-08 14:24     ` Borislav Petkov
2021-11-08 14:35       ` Borislav Petkov
2021-11-08 16:23         ` Steven Rostedt
2021-11-08 16:29           ` Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).