Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp609458rdb; Thu, 22 Feb 2024 13:42:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXcEo7DcX21k99uS0d5wKKk/roeULqIDGAlMh6XZpBovzECy9/tV+pNWCw7QYLFDsnTKhsq8fJnGdsGOKvvFwgCBsS5R9X+9osY9KzMXg== X-Google-Smtp-Source: AGHT+IGFNJQBglYfvElGUFWevA7NpOViDvrusRpWldc2N1djghHtuLOM4yGjkbgGtFBzw0fMwf4l X-Received: by 2002:a05:6a20:244e:b0:19b:673d:824d with SMTP id t14-20020a056a20244e00b0019b673d824dmr102443pzc.46.1708638153040; Thu, 22 Feb 2024 13:42:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708638153; cv=pass; d=google.com; s=arc-20160816; b=dDxqn8pX3W9d4LEPM9NTyu6w//cR+gcNSLzeASBHzUoifkpLd1tDatGL2fhkvnrE62 lFRy2+MQ0wQmaoUQuHSmv1rmT3KtzazjyoZ+ZgGFKJTwSBYJSnOKjdec3SeD3dLl0/w3 fTHx3GFH55UexuQp/jVoG1xP7lfrZh6lij+ukvd2zaQf+3PjQNfULMcT2EQmB02LpJjr s7PNxtuixjC1wOxuFmxq05/Wdqj8PW0O4MDxLjTpg8ComVdP3b3YpJRZGYa4Jr3YbeX+ QB1STJMDHCCiNmDlabEpqhz7XXXo293UPARgrN4IG3C0MIhG4TUplv6dk0THP7P1H9/0 b21A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:date:from; bh=0R7omLoisreIX2kcFjxEIAnsFhQNU9zRKOi2kYu33bU=; fh=Rs9EO3Ca6bmo6rbosaWzaUZUdXHi26C4y+TPRPR1704=; b=CYhO8mi/kjKrs/iIaMQpK0Jw4IQjo8Q06AM51TsKpjcvc9yh8PxSkuEQEF92cbid19 K63NWh3IH49rNeCNyhcW/3Vk8z1a+oh6Qv/c/cVFmm/Jtvp3XP9xnHQh+UAifAzcmMaH QJ7cMf+4I2vDiwf4yHVeY9Px4xsm/imNXHwoPaAkaiBMj/X2I4lrnful9bBpuaZ6jz1B 06aqFoAC64ka3J7tCWxkk80QSEgO4ps72GgXa5+dBHOQ2y9GqL2FTiiXkAYPgZ16fADj cK0iRC0R6omnK5KK4Q/UNP1/1modWA227a1f+Nt1gDaQJ9+G9bg73etEwXum7RKBc5PP OVbw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-77420-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77420-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id mf14-20020a170902fc8e00b001db9cab6c8asi7956216plb.603.2024.02.22.13.42.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:42:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77420-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-77420-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77420-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BA2A3284FD2 for ; Thu, 22 Feb 2024 21:42:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6BB2012D1F4; Thu, 22 Feb 2024 21:42:24 +0000 (UTC) Received: from fgw20-7.mail.saunalahti.fi (fgw20-7.mail.saunalahti.fi [62.142.5.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AFEF73F39 for ; Thu, 22 Feb 2024 21:42:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.142.5.81 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638144; cv=none; b=WOBsrG4A4U8CphoMxhLLT1rTASSnLTjJDnc19fYBvqG+b8tO5Ul/xlu8Q58YBCkFQu7VTLUcvIsYnVRV0I4wRtBv1Ad2o4WnN2iFpBQ2OmqobJaElBa8s21ftYYGVCR6QnbttMF5GLFeN7SEqUQibRkbt9UbLCm9ehGwTXE07sQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638144; c=relaxed/simple; bh=3qH6a911hvLZnHJF5DoZ8K6rR8//RgNHgPFdiHBY9tk=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=m5XRgWHe4lZsUOYrgyRJt6C6nPR2X11+70Iqt5rbVYK1KszTUPGyV5jk3S5D5soom4LGSFcbfa5P352tPAbndu45/aLtlQOWf4plVkUVYyAZwEyczqcgnSF5VOWMuveAkzR/GL1uly7ApbTQPY3S54Il0QDP2D7b68k/AkR90CE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=fail smtp.mailfrom=gmail.com; arc=none smtp.client-ip=62.142.5.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=gmail.com 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240222145838.12916-1-kabel@kernel.org> Thu, Feb 22, 2024 at 03:58:37PM +0100, Marek Beh?n 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@salutedevices.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 detached. > + * A few drivers initialize mutexes which they want destroyed before driver is > + * detached, for debugging purposes. > + * devm_mutex_init() can be used to omit the explicit mutex_destroy() call 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