Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5857984rdb; Thu, 14 Dec 2023 01:17:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrI6JvHw8BiPuL6mPJTkQsmWUbzPyrSnBPSaTj09oBf75hDxBvDHBS1P4IhotvfZm29iCk X-Received: by 2002:a05:6a00:b51:b0:6ce:3f02:108c with SMTP id p17-20020a056a000b5100b006ce3f02108cmr4933734pfo.22.1702545432177; Thu, 14 Dec 2023 01:17:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702545432; cv=none; d=google.com; s=arc-20160816; b=zRUGUEcfAKCCbWmKVBM6VhJKnGaFETuANEddtCE8wtXbvuxMnQBS0i3Pw3H9+f5/MB jC6Dm/Wd2ri3dDOfINGuO6kxLASaKNjody7z+RiRcDTcs42zSujx0VPczb04abABHFSu h4KoT3z0X2BpSMEd5fC1hrYT5skvEzWqsIQAAjQRSyj+fPt0KbcHxp4L1GH064qqe+kS ePttkg1uRdlV/uRPIlGrSkttSPUJDslZNHwdeJ95YzdYDlcgLvzYljMILwMIZzX+GVzX EN0CATjriV1cPZ3XRRRBqy6RGVkF4KbYDW1st5EHMf7CedarANXh/GswROmvl7c5FdtE HBww== 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 :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=aSXTliSLRPJwWKgirD+ynnpgvILXx2haTFF7t0rHIEw=; fh=rUyL/8fJAz+VSGUpWIQoer6bhbu2J8HbqWxndO4his8=; b=Xj5tH2yXYzv5RYtnVJSbQ9c/RZFL1NSyzZx3V1+3q56aiFPq5kag+da4ih+yUCyFAo KIP8YzejhMD8fhJVt2+uLST6Ixv5KHtmFi1qDdWH8vOOPfHG18uvszMig5ETqKDHWI4S cWPzd+pyJhfs+zPh75BMrWDJSdy9i+2VlLXt/55lIRtTlKuWpxi+EuwMdSu/QHUC+YDg zrKCAVpccwftoKoTSpXtFi3W2NwHzpl3xp2wZKTGEAzCNcMzqy6NKYYoXllz2t/qWrRB F5MoLSQe4evbq1O0B9nOxDea1RpdagxwKpTUCKAtwHeE1HIgOZz1avoq/e6/nfLWUc7r SiDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Nx5uV3a4; 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 bt9-20020a056a00438900b006cb64902ef3si10834097pfb.153.2023.12.14.01.17.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 01:17:12 -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=Nx5uV3a4; 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 5AB718076E61; Thu, 14 Dec 2023 01:17:09 -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 S232455AbjLNJQt (ORCPT + 99 others); Thu, 14 Dec 2023 04:16:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234416AbjLNJQr (ORCPT ); Thu, 14 Dec 2023 04:16:47 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3446D112 for ; Thu, 14 Dec 2023 01:16:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702545412; 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=aSXTliSLRPJwWKgirD+ynnpgvILXx2haTFF7t0rHIEw=; b=Nx5uV3a4jMfbpeuoFxbTM1pY9iPITeaqSUs7sbSOnrp+2fQxTe1LGlAu2SuxYJxHFYmLnk OcvFmZ47izKgCkQ9RFuEV2//E2xuT82q6mLe7KdH6vewF6+BVbDYjitqvN2ACf6vDtw/Yn zzxAAv6DTugGwp9SlHtVNgWeBNg40PE= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-435-DsH53_qdPEKXl44Rh_xE1Q-1; Thu, 14 Dec 2023 04:16:50 -0500 X-MC-Unique: DsH53_qdPEKXl44Rh_xE1Q-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-55223b294e0so724052a12.2 for ; Thu, 14 Dec 2023 01:16:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702545409; x=1703150209; 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=aSXTliSLRPJwWKgirD+ynnpgvILXx2haTFF7t0rHIEw=; b=atWf53smRfwpHyrvwOIcPrbxFEyz4DvG03HfQTFuf86PB0Vj9VWMyz3UVuXda8fD9Z F3C/8rHC0VGqmOlE7Et++zv1q+0MxYKXJriAwKmljEyLAHiEOwXnmZQj4JpSCWb6KnVd 1jbX9NZDOYhXeZaw6r9H/LSjaB1fhb08n6r5eYz5ReL7hZDv+K9g1lg49xBzRm6Pw2IS 6usWfBVhnrMtHO8vE4oAXqDZseB+rv7HWKJE5v1BLNEKBw/9jyKvhoIYoA+mbidSp3TJ fE/U8F9DOTbcCE2BKxYy/4bZSsK9kDc76DcejTmX5jLuCwEsPdsjluNM2dIqQCzsS9JZ IJQg== X-Gm-Message-State: AOJu0Yzg9w/PneZVa86WNLjab7sEvEzXKtOjmnF1RVASGpWswGIMwV8x A1Vp/6lVm916f5crknZl5rjS2xL7iSdlNu+HBbawy1BMLWZC7NNediHntowxcINLBa2rctIacPN TmAmVknWaccSAoOyhQ8YWPzsI X-Received: by 2002:a17:907:268e:b0:a1d:b7b9:3263 with SMTP id bn14-20020a170907268e00b00a1db7b93263mr2986289ejc.164.1702545409802; Thu, 14 Dec 2023 01:16:49 -0800 (PST) X-Received: by 2002:a17:907:268e:b0:a1d:b7b9:3263 with SMTP id bn14-20020a170907268e00b00a1db7b93263mr2986277ejc.164.1702545409439; Thu, 14 Dec 2023 01:16:49 -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 tq14-20020a170907c50e00b00a1f83646eb6sm7701080ejc.149.2023.12.14.01.16.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Dec 2023 01:16:48 -0800 (PST) Message-ID: <56e74264-6f98-4216-9f9a-e8f718375602@redhat.com> Date: Thu, 14 Dec 2023 10:16:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 03/11] devm-helpers: introduce devm_mutex_init To: Andy Shevchenko , George Stark Cc: pavel@ucw.cz, lee@kernel.org, vadimp@nvidia.com, mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu, mazziesaccount@gmail.com, peterz@infradead.org, mingo@redhat.com, will@kernel.org, longman@redhat.com, boqun.feng@gmail.com, nikitos.tr@gmail.com, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kernel@salutedevices.com References: <20231213223020.2713164-1-gnstark@salutedevices.com> <20231213223020.2713164-4-gnstark@salutedevices.com> Content-Language: en-US, nl From: Hans de Goede In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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]); Thu, 14 Dec 2023 01:17:09 -0800 (PST) Hi, On 12/13/23 23:38, Andy Shevchenko wrote: > On Thu, Dec 14, 2023 at 12:36 AM Andy Shevchenko > wrote: >> On Thu, Dec 14, 2023 at 12:30 AM 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 wrapper. >>> 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(). > > ... > >>> +#ifdef mutex_destroy >>> +static inline void devm_mutex_release(void *res) >>> +{ >>> + mutex_destroy(res); >>> +} >>> +#endif >>> + >>> +/** >>> + * devm_mutex_init - Resource-managed mutex initialization >>> + * @dev: Device which lifetime mutex is bound to >>> + * @lock: Pointer to a mutex >>> + * >>> + * Initialize mutex which is automatically destroyed when the driver is detached. >>> + * >>> + * Returns: 0 on success or a negative error code on failure. >>> + */ >>> +static inline int devm_mutex_init(struct device *dev, struct mutex *lock) >>> +{ >>> + mutex_init(lock); >>> +#ifdef mutex_destroy >>> + return devm_add_action_or_reset(dev, devm_mutex_release, lock); >>> +#else >>> + return 0; >>> +#endif >>> +} >> >> If this is going to be accepted, you may decrease the amount of ifdeffery. >> >> #ifdef ... >> #else >> #define devm_mutex_init(dev, lock) mutex_init(lock) > > More precisely ({ mutex_init(lock); 0; }) or as a static inline... With a static inline we are pretty much back to the original v3 patch. I believe the best way to reduce the ifdef-ery is to remove the #ifdef around devm_mutex_release() having unused static inline ... functions in .h files is quite common, so this one does not need a #ifdef around it and with that removed we are down to just one #ifdef so just removing the #ifdef around devm_mutex_release() seems the best fix. With that fixed you may add my: Reviewed-by: Hans de Goede to the patch and I'm fine with this being routed upstream through whatever tree is convenient. Regards, Hans