Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6287767rdb; Thu, 14 Dec 2023 13:50:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWiDyofZrLVRoN2vkestuOrWbUSNzHufLaaQaw0rvO45C6km5BwE3A8jmlBCrffrYHY2h8 X-Received: by 2002:a05:600c:164a:b0:40b:5e59:c566 with SMTP id o10-20020a05600c164a00b0040b5e59c566mr5485606wmn.144.1702590659619; Thu, 14 Dec 2023 13:50:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590659; cv=none; d=google.com; s=arc-20160816; b=I+7Q+qJw+acT3Y/15q2L2pKOHM181jNC2lDuA8gpDpFLrtbhIxjZQl6AzQaQSCMXvx KlEgxDubv/Eif0mWfyL4Jt71S4ZVL2iU0zcAxHb88KHR2xwigNhhLfM51WmjlDJcYNNR QdazIjkWUO0FjuRP9G/NnIu6s2D6RhWJX5GHeOBmMphTP1f+4JH1fwPqxvgU+cFgLfzC Y7qMcmUQisQXilXM6KXXLIj2edjtty+IN6aIgKRgaamIc2xN8vloFBKZIEEKKV0CGWT9 JmR7z1+67aKLT1aqc1P9k8QOBZo+FEft4L46xGR2/O4AOznjYsFk+BVF3LFak1l7SQ2B rUZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=N76kfg0ywmkR8TtMnOIAIbHKVc1yAqCoMGV3nn4LGko=; fh=J8Lm93tiU6ahMNOI6RT2HIXuuxM5nGyBO7VxFA72nv0=; b=qO97aoi4DSqLngMUZ9HcwwIKDh/d0i9rBIwRMLawWVposOlNhjoBXmeqasvQ/g/GJJ Nz9rI1ylT1aeGfYX/x+KTkmOlFMOSvEFvOxo+KCzRYzcmKHFDASFxG4+7MGnsmsmlvqi hFYT61tO0GKVdlsk1L8WLcwscfzFci4d0BXqUVHcqv6mkpll80UwXx/lNuYAnEKwXaIp heKMLbvB7pbmas5H35Id+n8Zcf1JXFppieLc61CNzhiw2ODEN7GdsvxXCg5PlzlBvpVN TFGJIg4xoPxaUO1m+BiA5tS9CVonZDNBWKY1QXzgd6LxJ9uu4dKlLAGn0z298nt1O4Xu U3Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A2Bg6dUh; spf=pass (google.com: domain of linux-kernel+bounces-163-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163-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 va5-20020a17090711c500b00987a0569370si6507764ejb.703.2023.12.14.13.50.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:50:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163-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=A2Bg6dUh; spf=pass (google.com: domain of linux-kernel+bounces-163-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163-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 E9B751F22693 for ; Thu, 14 Dec 2023 21:50:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3926966AA0; Thu, 14 Dec 2023 21:50:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="A2Bg6dUh" X-Original-To: linux-kernel@vger.kernel.org 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 462AF6E2C0 for ; Thu, 14 Dec 2023 21:48:52 +0000 (UTC) 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=1702590531; 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=N76kfg0ywmkR8TtMnOIAIbHKVc1yAqCoMGV3nn4LGko=; b=A2Bg6dUhyGeKx+QikkTQoVvqfEVMFhgB4hZ/RXgrwV934Parsx+2Iy8zj92dCjcsUIDGIc sHun8i8JIgVImbTO6OoTZtyA917HFrbRwkdmlAtBMkJu8hzIJhiVGA1OJfUjt8aLakQqI1 Ih14shd4kaBEzb/39+DPGB2/1K5Fq6s= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-502-BCArnhgcOo6X7wGnFiFIWQ-1; Thu, 14 Dec 2023 16:48:45 -0500 X-MC-Unique: BCArnhgcOo6X7wGnFiFIWQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 980A329AA3AF; Thu, 14 Dec 2023 21:48:44 +0000 (UTC) Received: from [10.22.17.13] (unknown [10.22.17.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 193C41C060B1; Thu, 14 Dec 2023 21:48:43 +0000 (UTC) Message-ID: <300d2131-87ef-48c1-b162-dcef0d8d5722@redhat.com> Date: Thu, 14 Dec 2023 16:48:42 -0500 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 v4 02/10] locking: introduce devm_mutex_init Content-Language: en-US To: Christophe Leroy , George Stark , "andy.shevchenko@gmail.com" , "pavel@ucw.cz" , "lee@kernel.org" , "vadimp@nvidia.com" , "mpe@ellerman.id.au" , "npiggin@gmail.com" , "hdegoede@redhat.com" , "mazziesaccount@gmail.com" , "peterz@infradead.org" , "mingo@redhat.com" , "will@kernel.org" , "boqun.feng@gmail.com" , "nikitos.tr@gmail.com" Cc: "linux-leds@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "kernel@salutedevices.com" References: <20231214173614.2820929-1-gnstark@salutedevices.com> <20231214173614.2820929-3-gnstark@salutedevices.com> <5c10f66c-3fd8-4861-994b-13e71c24f10a@redhat.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 On 12/14/23 14:53, Christophe Leroy wrote: > > Le 14/12/2023 à 19:48, Waiman Long a écrit : >> On 12/14/23 12:36, George Stark wrote: >>> Using of devm API leads to a certain order of releasing resources. >>> So all dependent resources which are not devm-wrapped should be deleted >>> with respect to devm-release order. Mutex is one of such objects that >>> often is bound to other resources and has no own devm wrapping. >>> Since mutex_destroy() actually does nothing in non-debug builds >>> frequently calling mutex_destroy() is just ignored which is safe for now >>> but wrong formally and can lead to a problem if mutex_destroy() will be >>> extended so introduce devm_mutex_init() >>> >>> Signed-off-by: George Stark >>> --- >>>   include/linux/mutex.h        | 23 +++++++++++++++++++++++ >>>   kernel/locking/mutex-debug.c | 22 ++++++++++++++++++++++ >>>   2 files changed, 45 insertions(+) >>> >>> diff --git a/include/linux/mutex.h b/include/linux/mutex.h >>> index a33aa9eb9fc3..ebd03ff1ef66 100644 >>> --- a/include/linux/mutex.h >>> +++ b/include/linux/mutex.h >>> @@ -21,6 +21,8 @@ >>>   #include >>>   #include >>> +struct device; >>> + >>>   #ifdef CONFIG_DEBUG_LOCK_ALLOC >>>   # define __DEP_MAP_MUTEX_INITIALIZER(lockname)            \ >>>           , .dep_map = {                    \ >>> @@ -127,6 +129,20 @@ extern void __mutex_init(struct mutex *lock, >>> const char *name, >>>    */ >>>   extern bool mutex_is_locked(struct mutex *lock); >>> +#ifdef CONFIG_DEBUG_MUTEXES >>> + >>> +int devm_mutex_init(struct device *dev, struct mutex *lock); >> Please add "extern" to the function declaration to be consistent with >> other functional declarations in mutex.h. > 'extern' is pointless and deprecated on function prototypes. Already > having some is not a good reason to add new ones, errors from the past > should be avoided nowadays. With time they should all disappear so don't > add new ones. Yes, "extern" is optional. It is just a suggestion and I am going to argue about that. > >>> + >>> +#else >>> + >>> +static inline int devm_mutex_init(struct device *dev, struct mutex >>> *lock) >>> +{ >>> +    mutex_init(lock); >>> +    return 0; >>> +} >> I would prefer you to add a devm_mutex_init macro after the function >> declaration and put this inline function at the end of header if the >> devm_mutex_init macro isn't defined. In this way, you don't need to >> repeat this inline function twice as it has no dependency on PREEMPT_RT. > It is already done that way for other functions in that file. Should be > kept consistant. I agree with you it is not ideal, maybe we should > rework that file completely but I don't like the idea of a > devm_mutex_init macro for that. devm_mutex_init() is not an API for the core mutex code. That is why I want to minimize change to the existing code layout. Putting it at the end will reduce confusion when developers look up mutex.h header file to find out what mutex functions are available. Cheers, Longman