Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp523172rdb; Thu, 22 Feb 2024 10:41:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX8ffLb/fcybUikHRAOnK0W154EZFtEZRlw1lbO/L1YbKnRFaNLI2mapJx2QkAvnb7nxRmI9iBymOI/NcPj5udc42FIWvD+3nwEmIWbxA== X-Google-Smtp-Source: AGHT+IGcAjT6J9FgSWWX5AFTC3k82C/fu2fpnoF2PK5XiPbQdvOzm4xI5t6mUYYT2t+rpRWQpVNT X-Received: by 2002:a17:906:27ce:b0:a3f:6e81:1801 with SMTP id k14-20020a17090627ce00b00a3f6e811801mr2452436ejc.6.1708627311551; Thu, 22 Feb 2024 10:41:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708627311; cv=pass; d=google.com; s=arc-20160816; b=X8le+tiZEEcOKHUZhhzZiCYoT3xpowmEOvEFO/j0uMMRRY9WCJjlYQdr/wxYXhMtWz qVm+Ck8G8KlK1f4pgdgvKQjwI8Xt6IyLNSjM/1qpa5YlvXLqDekG6gXTrJ31QZUihhT5 gMWr88/4XxBWkDDWnA7gCR5XifJ5Iw/5t/h7XSIEEQR+uOOxn8Skka9rB29uMhCrP9it pKGRBkF+fKc/++mhOHTcJXwTEAB639N3M/Y76nW0G77B8VN0o2CaOv3ut1n9I0v6NF31 g3OMpLywLCMWIoVxCAhm7JVAc0DDqyKRn43X2Dl9NCF6PCItRW2/XbusS/pPN//2rr8L /MPg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=IDF5rof44gEIb9jX4TIDVAFNvDzRBoYmWa48QZ9r6nQ=; fh=hdoqHqa1WZH2dL6ReYERdmxqZEwY1mJVy3bq7cXPZfE=; b=iAdOuV66AQMNAuqhc6I55vCx5EzUj9fAmujKCiwSkng6sbcmCJPvRJZpH7LvCfUrw2 KbfOAXxMTkrmXUOHne0HZ7lTaWai79QsXIoSIhtX+3cgWxgFrVn6atQHXM3f+pPzQOOF Z6/G867aPxz1cgZvviMPO4ZH4/T0cIlBjr2s3l/qcy5aWca4tirTJmKVXuwFFLg5kmb7 zgEFEKCseGt01BDrXPF3zsHlb0if53i2uBf20l3m+Tu0Fkxf1Q7DDM5Fy/bztiy40gUN rFhzbBf08RKwBHK/9NAJK+UKAy+FFvXNP4qD6Bjg+x9IDdDZpfA34YGFrT8o36abRpqh jzTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=g83gJR89; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-77150-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77150-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id go44-20020a1709070dac00b00a3e544f1944si4640671ejc.1021.2024.02.22.10.41.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 10:41:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77150-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=g83gJR89; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-77150-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77150-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3C45D1F239B1 for ; Thu, 22 Feb 2024 18:41:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB32B1448F1; Thu, 22 Feb 2024 18:33:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="g83gJR89" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 54D5A1448DF for ; Thu, 22 Feb 2024 18:33:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708626803; cv=none; b=YjN8ynp1eg3qyYaJno/yBVQs2KR4nV3tT1Ot/noEakwK9A1HIeONPEfpkwto1C1Lg1vm9pN0/p6/YzRsqQxH9XtpB95IxUuE3ft10TxEUUpO7pBxbfrMYhEYHMbxcPfp0Owj2fc59mR51gzz1RkyQNZAv/Y/1iMOvD/xFcmiaIo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708626803; c=relaxed/simple; bh=XSQAUK/U55m0KLayh5Wo5le7Vj1aHM53DbCd9IqoMdU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=teXSBf7iuVOEwbTEghPwiU5xPAeBKQ5UeRzOCfOSBHrDT/QO5OUzrIg0fZtBllo9OJEjt4dWGgw9tpLG4cI0skDqu1P2HgDUh4+CnHP3Vtn4+RY62/9pgDO6EDGqayGqTEJv6JsBj6i6XmlRu4049H3BzS6OYNHHohKbPida+8c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=g83gJR89; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708626800; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IDF5rof44gEIb9jX4TIDVAFNvDzRBoYmWa48QZ9r6nQ=; b=g83gJR897ZwJ8rUK8X1YTLxVGhoTuOhG56I2tSszT+J9GWM2FdvaR++WIq28LNW0Hy2egM kaGysJ/uG6CthGSsm8gZUa4h8CJyi+sFVtoPDIiZsyRZGNXX3kSvJBtPE4aaUj3CYTVTDe ji2b+4QZJvKMaFNGY4HLkK3kUzHtaog= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-qdYoPIW6PxCD_LyX9tY_nw-1; Thu, 22 Feb 2024 13:33:19 -0500 X-MC-Unique: qdYoPIW6PxCD_LyX9tY_nw-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a3f07bcba8cso909466b.3 for ; Thu, 22 Feb 2024 10:33:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708626797; x=1709231597; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IDF5rof44gEIb9jX4TIDVAFNvDzRBoYmWa48QZ9r6nQ=; b=NfwM/p95EWM9rUloxBzmsVElFLNUaIj3Io3bSKIf+8sP6Yk1gRZMkIXHZ5PqMeqfN3 wcEI2E+ygHYIsKOeiGN85ccQd6V4bQrR3ojEyf4vNLs07lh7A3SxUvSwPKNbntWsCYkU 6HOEi5+hBzVkjTH3+DmczrokmwT+VKofPXvSqwZq+R1UDeR08CYm45pzpZBmD9+K0xMD zszWaCKGKR3+3HagB3rnMHJU/BtBoBakI0asp9BCOXWNu8aeODmLryaxkSX8nz+EfT/O +jlHOy2tMQKU3puL9QoBNJGlfK4vdmvSarUOLIgzKAwiQmZQxZQ22cMZh2VIml9s2CUE Cd5g== X-Forwarded-Encrypted: i=1; AJvYcCUMnLDUUvvgzzmL1BzT9479aRjtP1RyJizq2bdegfz7+bO2FaoSjHHWBXYX4UrTr+f81Pi7TSKMhcayuZ648zNV+Q0fx0xR2eNZFwMb X-Gm-Message-State: AOJu0YwFYiEDVXK9HVpcp4MpVFWFbMTlgZR32fhhCUhcJE53bETDv2qv +Abt4olwD0GucNNiK0lPCTNfwXRB6FIIvLKtL7IRG15s/PQoThLuRTCZNJNS2ziVHwNRXgNhdCU OrbkFmBwO8nNbaF8FK7wTlpBL7MLcbm/VcsX5aktLBAdt/FqcXCVz1L/uVeT6feaWnkr13w== X-Received: by 2002:a17:906:3b52:b0:a3f:1ec7:8765 with SMTP id h18-20020a1709063b5200b00a3f1ec78765mr4781454ejf.8.1708626797707; Thu, 22 Feb 2024 10:33:17 -0800 (PST) X-Received: by 2002:a17:906:3b52:b0:a3f:1ec7:8765 with SMTP id h18-20020a1709063b5200b00a3f1ec78765mr4781437ejf.8.1708626797348; Thu, 22 Feb 2024 10:33:17 -0800 (PST) Received: from ?IPV6:2001:1c00:c32:7800:5bfa:a036:83f0:f9ec? (2001-1c00-0c32-7800-5bfa-a036-83f0-f9ec.cable.dynamic.v6.ziggo.nl. [2001:1c00:c32:7800:5bfa:a036:83f0:f9ec]) by smtp.gmail.com with ESMTPSA id lu16-20020a170906fad000b00a3d5efc65e0sm4854658ejb.91.2024.02.22.10.33.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Feb 2024 10:33:16 -0800 (PST) Message-ID: <7013bf9e-2663-4613-ae61-61872e81355b@redhat.com> Date: Thu, 22 Feb 2024 19:33:15 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] devm-helpers: Add resource managed version of mutex init To: Matthew Auld , =?UTF-8?Q?Marek_Beh=C3=BAn?= , linux-kernel@vger.kernel.org, Matti Vaittinen Cc: Linus Walleij , Bartosz Golaszewski , Lucas De Marchi , Oded Gabbay , =?UTF-8?Q?Thomas_Hellstr=C3=B6m?= , 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 References: <20240222145838.12916-1-kabel@kernel.org> <03e62bcf-137c-4947-8f34-0cbfcba92a30@intel.com> Content-Language: en-US, nl From: Hans de Goede In-Reply-To: <03e62bcf-137c-4947-8f34-0cbfcba92a30@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi, On 2/22/24 17:44, Matthew Auld wrote: > On 22/02/2024 14:58, Marek Behún wrote: >> 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. >> index 74891802200d..70640fb96117 100644 >> --- 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); > > Do you know if this this needs __always_inline? The static lockdep key in mutex_init() should be > different for each caller class. See c21f11d182c2 ("drm: fix drmm_mutex_init()"). That is a very good point. I believe that this should mirror mutex_init() and the actual static inline function should be __devm_mutex_init() which takes the key as extra argument (and calls __mutex_init()) and then make devm_mutex_init() itself a macro mirroring the mutex_init() macro. Regards, Hans > >> + >> +    /* >> +     * 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; >> +} >> + >>   #endif >