Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp772920lql; Mon, 11 Mar 2024 18:10:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWfxjZI8ofSKki1bm6qpY2QI8Hnjz7qy+GqRMVhOQxbNd1/3P9IVztx/XFHA8OPTVZqhlIfI42iDDg9atxkrpeJSskwUGOwdmDxFkjyHQ== X-Google-Smtp-Source: AGHT+IH+bOs5stwBHgmrwG6MsKSgldysQo+x+4yhp9goPWTs1IRpcV46UqAoOYOP/nMUTiFcV+xn X-Received: by 2002:a17:906:5642:b0:a44:74f6:a004 with SMTP id v2-20020a170906564200b00a4474f6a004mr4946520ejr.26.1710205833357; Mon, 11 Mar 2024 18:10:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710205833; cv=pass; d=google.com; s=arc-20160816; b=CWMWia+oe5KjjjgwOaWc7n+0WJV93luf1Xc6PbnjdhtX3XsspsGHrbkgcc6ucstHGs obS9Z5RQuFwMenq7w5VkR1SOeZBtPCaCG+9dUTGvUaZyYYEcwYvlmUYoqx654Iy4aBdz btCLpdBc35JRg7NrwxWFOaZcLcChVNBCUHBfMGNURPQrlRmgy5Ly96IehF26QGH6sB+D /7zxP2Erh95tCE/Z45EX0WhNrXiDbLQ2+5qoNBlqZQDwuIaVsVdJIuFpFQrlCT6l05mK sggIIbD/AgSSP44zw+4sYGbTgRlRoyzpVrWB8zx6NubmnTVvJGLzZH4GBN0x3x9oQ7h1 TjwA== 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:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=O2b5/RPP4rC6xUSDs7L8tllctKlCe9JUBBRdcxIDUUE=; fh=SrqvP/yL1VFE3BC560wpSrorstc2JUyAQQp/mX1zHtE=; b=QGzbCNIE+hE+7uqqNbmULekEbDTRUsCd/j/fWPlvj06IjM//Qp7yvpgKZkOyp06CI0 JOYwlZbAExBJKp8of+jJLcnELkIGbx/YRGRRRuw7IAQfje5xo6JILgk2M7w2Vo8oHjf8 Qi1pVucijD/OOkx0l2jhYxwxehYp2NtyDmzAoYGfgne3AqFKJ+dYMdHXhORhfw3cqeTm Eh6g0g1bTaxOo9dubOuT773Meg+OTFFZ/b+7N8sIB37EYh27dqEiR7FT22hQwEUtq3XQ sIZvoB8/kT4rEj2yijV82vdjs3P1qP61JUe9THUBRA+5PJWOM1Ug6tWw4s3A7BNYnxmp sHog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dTp18t9m; 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-99714-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99714-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id n17-20020a170906725100b00a45ac05036bsi2907091ejk.311.2024.03.11.18.10.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 18:10:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99714-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dTp18t9m; 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-99714-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99714-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 E54F11F221CF for ; Tue, 12 Mar 2024 01:10:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA74C10E6; Tue, 12 Mar 2024 01:10:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dTp18t9m" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 735177E2 for ; Tue, 12 Mar 2024 01:10:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710205827; cv=none; b=M6HzDKGVB8PeYpGQE7NQJbmfqOZPFbN9SxogYAj3KKUieC86593Spa15IiafAcvpFcxDFgDyDU/6CYf5T+zsaZI1jLf3bI6oOZozOX2z0qgnjhq3miJ9E1IslNrqqvHjfl/Rurhy/N/1/agX1H19g0tuAKjDuPPjtqjGZn0G7Nc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710205827; c=relaxed/simple; bh=2IKZoBxo6m2Ju8KnAoZJ5Oa2cVxc6yQ+NNpRpYhoXdk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=cNsBCO0CY4iwjJ2PxYCJ/qtqH81Rb/qIRRZ1Xxwd/fZddk8a9SNT9KkTj8qg7v3r7oLwbjKll0yCIQyYwMdHSs0qbS+C1XrHfPaCNmVQmjgDWVi6NOOfrakUmbsKbsL35GEyLIQ2se/xlcIVBVKRR2p66GMZA+Ufvr+sbedfADE= 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=dTp18t9m; arc=none smtp.client-ip=170.10.129.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=1710205824; 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=O2b5/RPP4rC6xUSDs7L8tllctKlCe9JUBBRdcxIDUUE=; b=dTp18t9mYTeZVxyZiT3dGRt35IBoK8URxBZ9Z2c8iwWKEnkABMBkWDVIFIjXAnS6Tgd1aa yi7skB74zDaSMCnmnCNf6gzTExqHknEpGDPe9cGo20fVI5QQko7oV/Hlm6R5+VPzufWpwR ltd1ZR0KrFWYPYY2hKtzV1DnRpFFRMI= 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-175-ctD-h0z2PQ61I25Kqa-naw-1; Mon, 11 Mar 2024 21:10:18 -0400 X-MC-Unique: ctD-h0z2PQ61I25Kqa-naw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 C98D43800E88; Tue, 12 Mar 2024 01:10:17 +0000 (UTC) Received: from [10.22.9.132] (unknown [10.22.9.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83DAF492BC6; Tue, 12 Mar 2024 01:10:16 +0000 (UTC) Message-ID: Date: Mon, 11 Mar 2024 21:10:16 -0400 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 v5 02/10] locking/mutex: introduce devm_mutex_init Content-Language: en-US To: George Stark , =?UTF-8?Q?Marek_Beh=C3=BAn?= Cc: andy.shevchenko@gmail.com, pavel@ucw.cz, lee@kernel.org, vadimp@nvidia.com, mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu, hdegoede@redhat.com, mazziesaccount@gmail.com, peterz@infradead.org, mingo@redhat.com, will@kernel.org, boqun.feng@gmail.com, nikitos.tr@gmail.com, kabel@kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kernel@salutedevices.com References: <20240307024034.1548605-1-gnstark@salutedevices.com> <20240307024034.1548605-3-gnstark@salutedevices.com> <20240307095639.b6utkbzr36liuu3p@kandell> <3d95ab40-2df5-4988-87be-568a628a0561@redhat.com> <20240307174414.4059d7ee@dellmb> 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.9 On 3/11/24 19:47, George Stark wrote: > Hello Waiman, Marek > > Thanks for the review. > > I've never used lockdep for debug but it seems preferable to > keep that feature working. It could be look like this: > > diff --git a/include/linux/mutex.h b/include/linux/mutex.h > index f7611c092db7..574f6de6084d 100644 > --- a/include/linux/mutex.h > +++ b/include/linux/mutex.h > @@ -22,6 +22,8 @@ >  #include >  #include > > +struct device; > + >  #ifdef CONFIG_DEBUG_LOCK_ALLOC >  # define __DEP_MAP_MUTEX_INITIALIZER(lockname)            \ >          , .dep_map = {                    \ > @@ -115,10 +117,31 @@ do {                            \ > >  #ifdef CONFIG_DEBUG_MUTEXES > > +int debug_devm_mutex_init(struct device *dev, struct mutex *lock); > + > +#define devm_mutex_init(dev, mutex)            \ > +({                            \ > +    int ret;                    \ > +    mutex_init(mutex);                \ > +    ret = debug_devm_mutex_init(dev, mutex);    \ > +    ret;                        \ > +}) The int ret variable is not needed. The macro can just end with debug_devm_mutex_init(). > + >  void mutex_destroy(struct mutex *lock); > >  #else > > +/* > +* When CONFIG_DEBUG_MUTEXES is off mutex_destroy is just a nop so > +* there's no really need to register it in devm subsystem. "no really need"? > +*/ > +#define devm_mutex_init(dev, mutex)            \ > +({                            \ > +    typecheck(struct device *, dev);        \ > +    mutex_init(mutex);                \ > +    0;                        \ > +}) Do we need a typecheck() here? Compilation will fail with CONFIG_DEBUG_MUTEXES if dev is not a device pointer. > + >  static inline void mutex_destroy(struct mutex *lock) {} > >  #endif > diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c > index bc8abb8549d2..967a5367c79a 100644 > --- a/kernel/locking/mutex-debug.c > +++ b/kernel/locking/mutex-debug.c > @@ -19,6 +19,7 @@ >  #include >  #include >  #include > +#include > >  #include "mutex.h" > > @@ -89,6 +90,16 @@ void debug_mutex_init(struct mutex *lock, const > char *name, >      lock->magic = lock; >  } > > +static void devm_mutex_release(void *res) > +{ > +    mutex_destroy(res); > +} > + > +int debug_devm_mutex_init(struct device *dev, struct mutex *lock) > +{ > +    return devm_add_action_or_reset(dev, devm_mutex_release, lock); > +} > + >  /*** >   * mutex_destroy - mark a mutex unusable >   * @lock: the mutex to be destroyed