From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 28F25C5478C for ; Thu, 22 Feb 2024 21:42:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LEqs2mrJi59hRqK/cSqjZRMQKR+4x1lZgjpAlpiu/cc=; b=ytCenssS3ZmBSt UAigXV7SzmWkiJQq/yaJ9Tu/Ifks4m1SYTAqQ2W/KJvJz9MFQZk0vAGsd8YP58cxQyGhfGyRDImm3 qLKr+vSnfDJMWhiBA/Q7rpHUNjzAEhGUy11fDJL8RrKSzcM3nhUQXinU/J4DalQ8ufvMevZPWncXU dI0JLBo9qWLcgeNwahQC7YchZmTxDwW0zoUoxfwWTOXSnaR+giHMluzL7Ic4Oj1I3NNbQtH2PrnKE pGVM2bZvyhlq2oOt95NpDcLXvFXBrsgbjVdr0QbVIXMOyMAoKDGngolDyhucqO2GxUmCcslhpnxYj p0ar6+YAupHv+GPot5VQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdGpj-00000006iqP-3A3d; Thu, 22 Feb 2024 21:42:23 +0000 Received: from fgw20-7.mail.saunalahti.fi ([62.142.5.81]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdGpf-00000006ijI-1QP8 for linux-arm-kernel@lists.infradead.org; Thu, 22 Feb 2024 21:42:21 +0000 Received: from localhost (88-113-26-217.elisa-laajakaista.fi [88.113.26.217]) by fgw20.mail.saunalahti.fi (Halon) with ESMTP id 3c868ecd-d1cb-11ee-b3cf-005056bd6ce9; Thu, 22 Feb 2024 23:42:13 +0200 (EET) From: andy.shevchenko@gmail.com Date: Thu, 22 Feb 2024 23:42:11 +0200 To: Marek =?iso-8859-1?Q?Beh=FAn?= Cc: linux-kernel@vger.kernel.org, Hans de Goede , Matti Vaittinen , Linus Walleij , Bartosz Golaszewski , Lucas De Marchi , Oded Gabbay , Thomas =?iso-8859-1?Q?Hellstr=F6m?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Aleksandr Mezin , Jean Delvare , Guenter Roeck , Pavel Machek , Lee Jones , Sebastian Reichel , Matthias Brugger , AngeloGioacchino Del Regno , linux-gpio@vger.kernel.org, intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, George Stark Subject: Re: [PATCH 1/2] devm-helpers: Add resource managed version of mutex init Message-ID: References: <20240222145838.12916-1-kabel@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240222145838.12916-1-kabel@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240222_134219_564715_07E8903C X-CRM114-Status: GOOD ( 19.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Thu, Feb 22, 2024 at 03:58:37PM +0100, Marek Beh=FAn kirjoitti: > A few drivers are doing resource-managed mutex initialization by > implementing ad-hoc one-liner mutex dropping functions and using them > with devm_add_action_or_reset(). Help drivers avoid these repeated > one-liners by adding managed version of mutex initialization. > = > Use the new function devm_mutex_init() in the following drivers: > drivers/gpio/gpio-pisosr.c > drivers/gpio/gpio-sim.c > drivers/gpu/drm/xe/xe_hwmon.c > drivers/hwmon/nzxt-smart2.c > drivers/leds/leds-is31fl319x.c > drivers/power/supply/mt6370-charger.c > drivers/power/supply/rt9467-charger.c Pardon me, but why? https://lore.kernel.org/linux-leds/20231214173614.2820929-1-gnstark@saluted= evices.com/ Can you cooperate, folks, instead of doing something independently? > --- a/include/linux/devm-helpers.h > +++ b/include/linux/devm-helpers.h > @@ -24,6 +24,8 @@ > */ > = > #include > +#include > +#include > #include > = > static inline void devm_delayed_work_drop(void *res) > @@ -76,4 +78,34 @@ static inline int devm_work_autocancel(struct device *= dev, > return devm_add_action(dev, devm_work_drop, w); > } > = > +static inline void devm_mutex_drop(void *res) > +{ > + mutex_destroy(res); > +} > + > +/** > + * devm_mutex_init - Resource managed mutex initialization > + * @dev: Device which lifetime mutex is bound to > + * @lock: Mutex to be initialized (and automatically destroyed) > + * > + * Initialize mutex which is automatically destroyed when driver is deta= ched. > + * A few drivers initialize mutexes which they want destroyed before dri= ver is > + * detached, for debugging purposes. > + * devm_mutex_init() can be used to omit the explicit mutex_destroy() ca= ll when > + * driver is detached. > + */ > +static inline int devm_mutex_init(struct device *dev, struct mutex *lock) > +{ > + mutex_init(lock); > + > + /* > + * mutex_destroy() is an empty function if CONFIG_DEBUG_MUTEXES is > + * disabled. No need to allocate an action in that case. > + */ > + if (IS_ENABLED(CONFIG_DEBUG_MUTEXES)) > + return devm_add_action_or_reset(dev, devm_mutex_drop, lock); > + else > + return 0; > +} Cc: George Stark -- = With Best Regards, Andy Shevchenko _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel