Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5957009rdb; Thu, 14 Dec 2023 04:48:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IG2Y9OS+R3ELPmUSG+7hTHTuYeKHl/fLbD74d01AvcgikJv69IBMPU0ArgZemFmvp5UEHYz X-Received: by 2002:a05:6e02:2145:b0:35d:69fd:7db3 with SMTP id d5-20020a056e02214500b0035d69fd7db3mr11374890ilv.0.1702558119036; Thu, 14 Dec 2023 04:48:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702558119; cv=none; d=google.com; s=arc-20160816; b=cKz2AqlFirAU2xi3Upa9nhHaLIZMv5vG/QwgDnEoXNR2M1D2unlupd2JLxZ1EI/ih/ J9QRq4XCrwyYF2KRFBIMF8dMbmXSwQo4y4QI18VqWitAaDRgMiq8WbDviDw3FbJws6Lf L1Wc0H6fIsvF+vrwTulMSZDCT9bRfJcMBLXmK38TdJSMef2KuNeF9IwawOOGAQn4O3iV bqTRLF1VxGZI32B3c64VLZtYDAxzVMJq9B3/dcyIZ2aI8cHnXAioyN19WmKnQMhHXYVH l1j5TRMlXeHZTdsznbWzoxBkb20XFvUZUxmQc2CaeCP7CMfH0MZ12ns68a9x34D8eXZj tEYQ== 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:dkim-filter; bh=u+Z5N++7kSFY5F/c2vJ7dRETDl74LEfCFys2YGreP0U=; fh=uIEoyYoujgvcCNtQd/I/w/tSAEpS2Zj1RQZu0ZPGoFo=; b=LVoC3ECaQPiTY6ikUk/tkVphVvYnUSVV49ekEfTnXvyOSbtL1MylFMstwWxTrxho7G Ujm6o71dYflxmjybQU7qaP0aQ3sUKpfAbxjFWdnqixMBhc5mAmLc65ev1shrLLO1I2LX CywK83u8T9GMnpNNfWKjDNIB5yIj6LPGsYu6apJ3FJF+cOOZvVSiPLR/GzQZosI3/t9X /SjCLKgxLa9tJjXeo1oetDuUh5SQ61Ou1fb/Dqvc6Nf3J6GQAAGRwbUQqhUvSDNU30Re HQ1F1LtCWRsjomUHkQIPZJ+Jmg2KrWJnYUKXX0KvtVJkiq2+mGdUvnBWNy9Ouk8gz5m0 QWJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=EjoAk9t3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=salutedevices.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id by12-20020a056a02058c00b005c66c2d0a5csi11647388pgb.484.2023.12.14.04.48.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 04:48:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=EjoAk9t3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=salutedevices.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8E54B801CFF9; Thu, 14 Dec 2023 04:48:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573132AbjLNMsT (ORCPT + 99 others); Thu, 14 Dec 2023 07:48:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573144AbjLNMsS (ORCPT ); Thu, 14 Dec 2023 07:48:18 -0500 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0DD0118; Thu, 14 Dec 2023 04:48:21 -0800 (PST) Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 2BE86120006; Thu, 14 Dec 2023 15:48:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 2BE86120006 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1702558099; bh=u+Z5N++7kSFY5F/c2vJ7dRETDl74LEfCFys2YGreP0U=; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type:From; b=EjoAk9t3ili75t5nFo1YFyObpi37mVffM2APXHrDL7UCttExpyNB7Q79fDnLYD8K9 g6gvOsiXawD2nktGF7NhcGA1xfX8GcszTJWfHYYeGz2v2QBMz1JvPqrU18bY0hJ8M3 CC11DtjBWbEdbczxzUtpBugN0iEE98f+al793cKa7EaCzSoXt9Ck1lIjZ3yTmqMo84 4e6ec79vYEtt412a62fqqvhGIIZ/lUeN5wue8GxK7p5LwGZxJGMqHt/+Cd/sGoszx+ rK2lRlUlxlf+GRbzgNCJ2dUNAbg5CviwmAtq2dUPz0MeXuL+5O+J+egZCQN2qFH6Qx AZIJQx/FS38Qg== Received: from smtp.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Thu, 14 Dec 2023 15:48:18 +0300 (MSK) Received: from [192.168.1.143] (100.64.160.123) by p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 14 Dec 2023 15:48:18 +0300 Message-ID: <99882775-af52-49ea-b17d-f3d1f23f8bbe@salutedevices.com> Date: Thu, 14 Dec 2023 15:48:18 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 03/11] devm-helpers: introduce devm_mutex_init To: Christophe Leroy , "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" , "longman@redhat.com" , "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: <20231213223020.2713164-1-gnstark@salutedevices.com> <20231213223020.2713164-4-gnstark@salutedevices.com> <80881d5d-3ae9-4580-84c1-f25b421cc518@csgroup.eu> Content-Language: en-US From: George Stark In-Reply-To: <80881d5d-3ae9-4580-84c1-f25b421cc518@csgroup.eu> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 182110 [Dec 14 2023] X-KSMG-AntiSpam-Version: 6.1.0.3 X-KSMG-AntiSpam-Envelope-From: gnstark@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 7 0.3.7 6d6bf5bd8eea7373134f756a2fd73e9456bb7d1a, {Tracking_uf_ne_domains}, {Tracking_from_domain_doesnt_match_to}, lore.kernel.org:7.1.1;100.64.160.123:7.1.2;smtp.sberdevices.ru:5.0.1,7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;salutedevices.com:7.1.1;127.0.0.199:7.1.2, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean, bases: 2023/12/14 09:55:00 X-KSMG-LinksScanning: Clean, bases: 2023/12/14 09:55:00 X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2023/12/14 10:50:00 #22693095 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-0.9 required=5.0 tests=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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 14 Dec 2023 04:48:35 -0800 (PST) Hello Christophe On 12/14/23 13:06, Christophe Leroy wrote: > > ... > > So you abandonned the idea of using mutex.h ? I'm not the one who make a choice here. The patch [1] you're talking about was seen by everyone but it seems like no one had shown interest. For me personally approach with #define mutex_destroy is not very usual but if even slight mixing device with mutex.h is unacceptable what else can we do? Avoiding the need to allocate devm slot for empty mutex_destroy is more important. Should I make series #4 with the patch [1] to give it a last chance? [1] https://lore.kernel.org/lkml/377e4437-7051-4d88-ae68-1460bcd692e1@redhat.com/T/#m3f6df30ffccaccb1df4669a327f349164f572931 > I can't see the point to spread mutex functions into devm-helpers.h > > Adding a mutex_destroy macro for this purpose looks odd. And if someone > defines a new version of mutex_destroy() and forget the macro, it will > go undetected. > > Usually macros of that type serve the purpose of defining a fallback > when the macro is not defined. In that case, when someone adds a new > version without defining the macro, it gets detected because if > conflicts with the fallback. > But in your case it works the other way round, so I will just go undetected. > > For me the best solution remains to use mutex.h and have > devm_mutex_init() defined or declared at the same place as mutex_destroy(). > > >> >> Signed-off-by: George Stark >> --- >> include/linux/devm-helpers.h | 27 +++++++++++++++++++++++++++ >> 1 file changed, 27 insertions(+) >> >> diff --git a/include/linux/devm-helpers.h b/include/linux/devm-helpers.h >> index 74891802200d..4043c3481d2e 100644 >> --- a/include/linux/devm-helpers.h >> +++ b/include/linux/devm-helpers.h >> @@ -24,6 +24,7 @@ >> */ >> >> #include >> +#include >> #include >> >> static inline void devm_delayed_work_drop(void *res) >> @@ -76,4 +77,30 @@ static inline int devm_work_autocancel(struct device *dev, >> return devm_add_action(dev, devm_work_drop, w); >> } >> >> +#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 >> +} >> + >> #endif >> -- >> 2.25.1 >> -- Best regards George