Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1033003rdb; Wed, 6 Dec 2023 07:01:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmbRiNgG0hSHX7a8lEMQHle33glYaXeYKeaJ7LQyny8JyS2zFfltYIetHNYQPk765xiVMk X-Received: by 2002:a05:6870:1d4:b0:1fa:2263:10ad with SMTP id n20-20020a05687001d400b001fa226310admr1578380oad.25.1701874887659; Wed, 06 Dec 2023 07:01:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701874887; cv=none; d=google.com; s=arc-20160816; b=QCLQblUVJKivhXNcE70s12LgjzWDnKNdMTr7RoGFcT/iu4HoMtoFYDVr4VQU+fOHRW mWgGR/KXKGmRMn++qHDyv3ap6eNeuKp3Jm3qtjUg2qR3G9xHSVcQsRA6Syd8qCYvnuo0 Gzk/+MdGFL1wcnggrzutTtx2I0VpfuydeyiuhCe7OBbIan0S5qXYVAhzg3Sbm/U2iIYk GFXphxcRWfnnB/cHy3DX6yDLn9OcTHUGE67x8Dh/LiZBDr1YDEGS3XjMqGZBAF9WpdIU nQrK7jMvgpLcHisWCYkGdNxxcFtXXQCrvCDHoR5K01iXRoJZbcheR3cGu0tSwr2s85U4 YzjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=dOg7HAEWpXF9CsdFUNxvCGFVvkmTsr7J73fSYQBJM0c=; fh=2xS4vPsSKLqOfCXvwyh1Lj0i16ljSe14bL9y2j4AHpU=; b=sicW21vlhxWr/iMCTbAG68WxNnfTcOiboi9gkVNjF7nMfqe8vIw6JKG0xF+KZ8TO1k mfA5YLvPwTwOagW+injREOBAnS9beyRI/NqERWaekxDP422O0S+JJ7lANVJ/DLoUxszv L3pUMwfRFmfTEVtZwc2doKgWejeUflv+I8Ls7qhjmuZYMjhvHQN8eVo53Zw3U6fhoIdT iDeNWKXI4CrWuAkcQGVzBcZf9+7/TieskyXNSBw1BmsVbnA7FZwHRYVB1ra8MuGudvhY ileeuV9vns/O5gOjnBmVSQ7/G9dPqjQQoNoSikKVGLBsd+qe1pA86iEsrmiSNEFwL1ZG xobw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QyjvJBei; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id fq44-20020a0568710b2c00b001fafe0c0283si9337oab.276.2023.12.06.07.01.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 07:01:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QyjvJBei; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 34DA58087208; Wed, 6 Dec 2023 07:01:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442179AbjLFPBB (ORCPT + 99 others); Wed, 6 Dec 2023 10:01:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378993AbjLFPBA (ORCPT ); Wed, 6 Dec 2023 10:01:00 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F5401BD for ; Wed, 6 Dec 2023 07:01:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701874865; 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=dOg7HAEWpXF9CsdFUNxvCGFVvkmTsr7J73fSYQBJM0c=; b=QyjvJBeiX1E84Zvw7rTOUqT+H36yZ0Lqq+18bnnx1rZNxWBJUhgB5wzyn2399l24RscI/E 5XX1u69uY7vnwry59540sDMUPn+pxsHj1epZCStocEJgBaQBih03qGAQiOxAxnMhXGgxXD oN9R5ma/aosQaXsaMVXP5DIm4wuUGc4= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-76-d7XZzaunPCGakobKpF9_DQ-1; Wed, 06 Dec 2023 10:01:04 -0500 X-MC-Unique: d7XZzaunPCGakobKpF9_DQ-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a1cfd84b473so105261966b.1 for ; Wed, 06 Dec 2023 07:01:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701874863; x=1702479663; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dOg7HAEWpXF9CsdFUNxvCGFVvkmTsr7J73fSYQBJM0c=; b=BkuUtNRHND5Gx3QHd2lk1AcE6P3qyUs4ivlrGJqq7mycL5pvQrF8mzSZk/82G3NxHY eOXK0LAWka1IAPZVa6uQgvQeOwEyo9LfFl9K2hqwzFEupM4chArJqsgzoNWzr7jqr4P6 arkMR+ahE1z2VFTopgrfb3BdSHCEELuoZ3Uk7JWIkgE3/jh4m2tn2sz/X6bqT+7Su8Kb +svetopQFJydsrVPlOlpI9Khaxzw5K9n/9bl6yHlxcXGKBijIHfnp9/7qhlZPTeCInUG 7CcMhmnwDrPoRm2+ZWrMsW+H7nLXnMSzcL5TVpwjKaB3dKChint5M8CMlh5jr1cb54ic WYFA== X-Gm-Message-State: AOJu0Ywyrqa/YHFVsg5qDdHWKW9W1GMEhIfA1hYRdSeXTRJH9EXibrMT bhO+vSQCzhZvXy/4zWMmkKau+l/fn40oCRG/C3SiIZv358j25bej3o1yGqIjk1M0Zv2+/T64zs8 SEbFbhgx6n6kIcdG/GsbNeRSz X-Received: by 2002:a17:906:207:b0:9ad:8a96:ad55 with SMTP id 7-20020a170906020700b009ad8a96ad55mr3351772ejd.14.1701874863013; Wed, 06 Dec 2023 07:01:03 -0800 (PST) X-Received: by 2002:a17:906:207:b0:9ad:8a96:ad55 with SMTP id 7-20020a170906020700b009ad8a96ad55mr3351759ejd.14.1701874862671; Wed, 06 Dec 2023 07:01:02 -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 t7-20020a1709063e4700b00a1dc7e789fbsm31636eji.21.2023.12.06.07.01.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 Dec 2023 07:01:02 -0800 (PST) Message-ID: <81798fe5-f89e-482f-b0d0-674ccbfc3666@redhat.com> Date: Wed, 6 Dec 2023 16:01:01 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 01/10] devm-helpers: introduce devm_mutex_init Content-Language: en-US, nl To: George Stark , pavel@ucw.cz, lee@kernel.org, vadimp@nvidia.com, mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu, mazziesaccount@gmail.com, andy.shevchenko@gmail.com, jic23@kernel.org Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kernel@salutedevices.com References: <20231204180603.470421-1-gnstark@salutedevices.com> <20231204180603.470421-2-gnstark@salutedevices.com> From: Hans de Goede In-Reply-To: <20231204180603.470421-2-gnstark@salutedevices.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 06 Dec 2023 07:01:21 -0800 (PST) Hi George, On 12/4/23 19:05, George Stark wrote: > Using of devm API leads to 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() is > extended so introduce devm_mutex_init(). > > Signed-off-by: George Stark > --- > include/linux/devm-helpers.h | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/include/linux/devm-helpers.h b/include/linux/devm-helpers.h > index 74891802200d..2f56e476776f 100644 > --- a/include/linux/devm-helpers.h > +++ b/include/linux/devm-helpers.h > @@ -76,4 +76,22 @@ static inline int devm_work_autocancel(struct device *dev, > return devm_add_action(dev, devm_work_drop, w); > } > > +static inline void devm_mutex_release(void *res) > +{ > + mutex_destroy(res); > +} > + > +/** > + * devm_mutex_init - Resource-managed mutex initialization > + * @dev: Device which lifetime work is bound to > + * @lock: Pointer to a mutex > + * > + * Initialize mutex which is automatically destroyed when driver is detached. > + */ > +static inline int devm_mutex_init(struct device *dev, struct mutex *lock) > +{ > + mutex_init(lock); > + return devm_add_action_or_reset(dev, devm_mutex_release, lock); > +} > + > #endif mutex_destroy() only actually does anything if CONFIG_DEBUG_MUTEXES is set, otherwise it is an empty inline-stub. Adding a devres resource to the device just to call an empty inline stub which is a no-op seems like a waste of resources. IMHO it would be better to change this to: static inline int devm_mutex_init(struct device *dev, struct mutex *lock) { mutex_init(lock); #ifdef CONFIG_DEBUG_MUTEXES return devm_add_action_or_reset(dev, devm_mutex_release, lock); #else return 0; #endif } To avoid the unnecessary devres allocation when CONFIG_DEBUG_MUTEXES is not set. Regards, Hans