Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp25872pxb; Mon, 8 Nov 2021 09:10:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJVbQIMB/qnqHklwnGhdP6bZEj/Lib9PiCnhcbK3aC1w7+F5zG2GF5N7++W6wNIuz3qqDT X-Received: by 2002:a02:cc91:: with SMTP id s17mr524755jap.3.1636391429658; Mon, 08 Nov 2021 09:10:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636391429; cv=none; d=google.com; s=arc-20160816; b=gZz2ognTfhrhaFittE11fr69MpLFlQ8/lM2mKxhJmE1rEgXAzeBKs7pb+Y+hJVRe9U 5y6eWma9Hj+b7O01u3+DmSQ5lwsbuNpvnbePptMl5A6I/3ObkYZW3DbiG3jlYey09FpD hMOYXY3v47lbXeGUD1DqXSMb6jEUllyj8CSZIVOFz5v8oUHgyfD8ZT+8jwSSkln1ecXv asNVtJFawa4t4L/yiGyuhw1wit9K2P/FuC6vDgjyLghiJJA0N7e74HUNogOdLQfUnEdU m5Urrnrw9P+dtDFjG+uMIeglyul6tdZDILOjq+g2O0BgXCwAX951A4R09gLwd05igUfR nmRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=B6oOQ1q4gjLTOu5usgfET43xDRmf4tLazw1TZ6CRXFw=; b=NHzejYydvLC8ACwYUJBAT4y/zl+DqjbgRNbMz9VSl+FXsHzBYQFGPWOSU+64N0L9m8 Hveh3u/7aTgUTzE5LIBnDOqSWqXFzyaMkrAhysBtcKiScVu215Upew0NrJ8uDCdAc/AQ JO9z9HmgC6wtZXUam+7cIB1q+YPGL1jgpMAec3JQrws08go+G/PMwOU6OGF9LUS2hTWI c0SqEByabdnEfI+BYms74aQDSS2R3e5yxZdxsKodRXvAcrfDoD+lX10CAy/8/fD1iOZc BWbMi/aIbzOBQ+8veA81S0c78icW3kh7D1YmipLNKRBhI5XyDrbFZuJ3+tCy6Rzgl/sK 14Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=Upd25Hzf; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 1si21033029ilz.178.2021.11.08.09.10.10; Mon, 08 Nov 2021 09:10:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=Upd25Hzf; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240524AbhKHOim (ORCPT + 99 others); Mon, 8 Nov 2021 09:38:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239345AbhKHOim (ORCPT ); Mon, 8 Nov 2021 09:38:42 -0500 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0AEAC061570; Mon, 8 Nov 2021 06:35:57 -0800 (PST) Received: from zn.tnic (p200300ec2f331100b486bab6e60d7aaf.dip0.t-ipconnect.de [IPv6:2003:ec:2f33:1100:b486:bab6:e60d:7aaf]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 1A75E1EC01FC; Mon, 8 Nov 2021 15:35:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1636382156; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=B6oOQ1q4gjLTOu5usgfET43xDRmf4tLazw1TZ6CRXFw=; b=Upd25HzfEqhrG5TAXmV4X7VLTXjG+2mbIZvAcNaA5XdFGwWxC22cjGdH367SqKuC2YI35V XePkT+plNO8Rcdx9qRLbflORPHDjzc4q/HfinrM2oVoUmKJ3f3FbXqZbeiIVI7zzNRafCc NDGlsVX5pxz7i7hCYlNzvvCrAxbHbAs= Date: Mon, 8 Nov 2021 15:35:50 +0100 From: Borislav Petkov To: Alan Stern , Geert Uytterhoeven Cc: LKML , Arnd Bergmann , Ayush Sawal , Greg Kroah-Hartman , Rohit Maheshwari , Steven Rostedt , Vinay Kumar Yadav , alsa-devel@alsa-project.org, bcm-kernel-feedback-list@broadcom.com, intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-crypto@vger.kernel.org, linux-edac@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-iio@vger.kernel.org, linux-leds@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linux-pm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-remoteproc@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-sh@vger.kernel.org, linux-staging@lists.linux.dev, linux-tegra@vger.kernel.org, linux-um@lists.infradead.org, linux-usb@vger.kernel.org, linux-xtensa@linux-xtensa.org, netdev@vger.kernel.org, openipmi-developer@lists.sourceforge.net, rcu@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org, xen-devel@lists.xenproject.org Subject: Re: [PATCH v0 00/42] notifiers: Return an error when callback is already registered Message-ID: References: <20211108101157.15189-1-bp@alien8.de> <20211108101924.15759-1-bp@alien8.de> <20211108141703.GB1666297@rowland.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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