Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1597737rdb; Thu, 7 Dec 2023 04:01:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFa+Kkc9HuNyIX3EiZH98NQqwCBCg8b3C/xgPvMI2LRQqsYKQ8lNIZmosEgF3FzLyqVTp4p X-Received: by 2002:a05:6a20:a486:b0:190:e59:f154 with SMTP id y6-20020a056a20a48600b001900e59f154mr416797pzk.18.1701950470393; Thu, 07 Dec 2023 04:01:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701950470; cv=none; d=google.com; s=arc-20160816; b=0vYhEjgIHozpgKG1C35ChH+A2n2oebOD+Xd0wVAZLfmSFoedxxCj7xKkoKsFHjYmfY 5e+UIGoReVDN0wPKs8eO7Q8BIpwvcrQ+Y3tWLkaXZY+jpk4n26pTWn548mJHhk2h32Cm KmzP8EoAzmhl3Q+YhYDWrfBfgCadrSWWJRuNVkfloAApCNEkQUFYq/YyArCCgzbMHJVC DvhbzZu5kxG80ZQvAZ3zg5mX5zu/GibS5t6NXQg2P4Sm4Oyl8+hvvPtMipRYCnn44cgF yAYu8HFy2fhRaKKLhO76gwccdF3L3VhTcqo9E60h1CjW69IwNclkPkAXJykvvazkmbHg gZSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=8N1+cn+fBSeHCGuo21Zugsp7Q1cczJw+MFPsoqSobZY=; fh=4WewCDtqXu7DRIA4vABwqb91Z7MJbizJiGJPATU6N/g=; b=cpfXdWu397vZcmd8QcnSvi5BhivN+FAOdlSv5BZXH6kmDwm2QItK6foSirq9cQbIN5 0WFnU2hGgQ8qFxY6hB3Ph7vRljfEwzR2P2u63v/jLD5N4o2Y0rjhiX6Fplx6+yudZd5o jFNvXsJYH1GdyZ6UXcg8o5vQsrK12SwEiRqg2WtDPkFMU7pUJGsrT0E99gvJMGtscJdO SsVhb/u3fFIqH5lRNlVESt7zbeGs7bCRdTnewd7DeM+fseFvGioS1wvM01JHHlV21+wG t7PQlQSAbhDiq2if8Cdoz4Ii7TYS4HrU53Mg2a0ZtibCF8uWQrAK8B1SWEfCQf27VhNy bjsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=kcR7eQ5T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id q23-20020a656857000000b005c69a12d683si1039029pgt.776.2023.12.07.04.01.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 04:01:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=kcR7eQ5T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id B4D9280A1E05; Thu, 7 Dec 2023 04:00:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232527AbjLGMAQ (ORCPT + 99 others); Thu, 7 Dec 2023 07:00:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232555AbjLGMAN (ORCPT ); Thu, 7 Dec 2023 07:00:13 -0500 Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 200D110CA; Thu, 7 Dec 2023 04:00:18 -0800 (PST) Received: by mail-qk1-x734.google.com with SMTP id af79cd13be357-77d6f853ba0so42029685a.0; Thu, 07 Dec 2023 04:00:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701950417; x=1702555217; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=8N1+cn+fBSeHCGuo21Zugsp7Q1cczJw+MFPsoqSobZY=; b=kcR7eQ5T/lKtqsRWoAx/y1o4g/R6A+tkpk4MAYJ/Zp9/xCM0QhAii1wCDYkbe4BIXr YEGbKLVncH4ocj6toT8d0rctejB7d85IAQLCAy/v5Qoup/OpKK+RnxeBCn2oRkVgqFTg SLtbWXvQ8OqXx3tXiBnP6cM1ZFBF0qhqrxP1qqtNrtd1U6r4mNhNclU11qcB+qBO+yIA uYZCpoSamoPf8cZ4Ig7Iw1ted+bPVsOH8L9A5ACzga2DHZKA+oRazG4lynENcfzHotJc Z9FSfI0FNUZJU6fJLHghZ+x9O+yfMS7QJcCQwS8HJrLx/kDODIfL0GpIZfv+omQI8tqb pqPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701950417; x=1702555217; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8N1+cn+fBSeHCGuo21Zugsp7Q1cczJw+MFPsoqSobZY=; b=akQ9wUylxJGOwOBIRjB10nQb7Trc889IUsigmbH8quyjotMxrsf/xNw/3KHX9jmFhm X3MVsi+BaPd70t2MTT9sqjgmwBzGIrH231tCHKc0FRC16UTwv26NRrEJk1XdQmNtI1IM I7EkemHGGaY4Etkh9sDfI87FYZqv9VnqWAfVC0ok5u+6CYenvSxkZzBuhUEun4NGzDte +v7SgLLtCNXwUWFch4pVmTZsx9fGMgx1+PGMYCIVqMn/ZOIqdxOEfAdWfscmHeNTt+jZ dQbKuRVamMT4AQQ2sJn2slonplXKqpbxIkMLObmTOcgl35YUUqgCeam0Bxbh0gHqPbrv sqdg== X-Gm-Message-State: AOJu0Yxin22VmXHgmCcBGzqjMugydx/jE4r1jGFNaoxso8Yo3B3amuCl tG89Wsppy4uarSLVuDjd2r5NieYm4iTCWhG28nI= X-Received: by 2002:a05:620a:2486:b0:77f:34bf:5593 with SMTP id i6-20020a05620a248600b0077f34bf5593mr1943614qkn.17.1701950417106; Thu, 07 Dec 2023 04:00:17 -0800 (PST) MIME-Version: 1.0 References: <20231204180603.470421-1-gnstark@salutedevices.com> <20231204180603.470421-2-gnstark@salutedevices.com> <81798fe5-f89e-482f-b0d0-674ccbfc3666@redhat.com> <29584eb6-fa10-4ce0-9fa3-0c409a582445@salutedevices.com> <17a9fede-30e8-4cd5-ae02-fe34e11f5c20@csgroup.eu> <2a68534b-9e64-4d6e-8a49-eeab0889841b@salutedevices.com> In-Reply-To: <2a68534b-9e64-4d6e-8a49-eeab0889841b@salutedevices.com> From: Andy Shevchenko Date: Thu, 7 Dec 2023 13:59:40 +0200 Message-ID: Subject: Re: [PATCH v2 01/10] devm-helpers: introduce devm_mutex_init To: George Stark Cc: Christophe Leroy , Hans de Goede , "pavel@ucw.cz" , "lee@kernel.org" , "vadimp@nvidia.com" , "mpe@ellerman.id.au" , "npiggin@gmail.com" , "mazziesaccount@gmail.com" , "jic23@kernel.org" , "peterz@infradead.org" , Waiman Long , mingo@redhat.com, will@kernel.org, boqun.feng@gmail.com, "linux-leds@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "kernel@salutedevices.com" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 07 Dec 2023 04:00:39 -0800 (PST) On Thu, Dec 7, 2023 at 1:23=E2=80=AFAM George Stark wrote: > On 12/7/23 01:37, Christophe Leroy wrote: > > Le 06/12/2023 =C3=A0 23:14, Christophe Leroy a =C3=A9crit : > >> Le 06/12/2023 =C3=A0 19:58, George Stark a =C3=A9crit : > >>> On 12/6/23 18:01, Hans de Goede wrote: > >>>> On 12/4/23 19:05, George Stark wrote: ... > >>>> 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. > >>> > >>> Honestly saying I don't like unnecessary devres allocation either but > >>> the proposed approach has its own price: > >>> > >>> 1) we'll have more than one place with branching if mutex_destroy is > >>> empty or not using indirect condition. If suddenly mutex_destroy is > >>> extended for non-debug code (in upstream branch or e.g. by someone fo= r > >>> local debug) than there'll be a problem. > >>> > >>> 2) If mutex_destroy is empty or not depends on CONFIG_PREEMPT_RT opti= on > >>> too. When CONFIG_PREEMPT_RT is on mutex_destroy is always empty. > >>> > >>> As I see it only the mutex interface (mutex.h) has to say definitely = if > >>> mutex_destroy must be called. Probably we could add some define to > >>> include/linux/mutex.h,like IS_MUTEX_DESTROY_REQUIRED and declare it n= ear > >>> mutex_destroy definition itself. > >>> > >>> I tried to put devm_mutex_init itself in mutex.h and it could've help= ed > >>> too but it's not the place for devm API. > >>> > >> > >> What do you mean by "it's not the place for devm API" ? > >> > >> If you do a 'grep devm_ include/linux/' you'll find devm_ functions in > >> almost 100 .h files. Why wouldn't mutex.h be the place for > >> devm_mutex_init() ? > mutex.h's maintainers believe so. > > https://lore.kernel.org/lkml/070c174c-057a-46de-ae8e-836e9e20eceb@saluted= evices.com/T/#mb42e1d7760816b0cedd3130e08f29690496b5ac2 > > > > Looking at it closer, I have the feeling that you want to do similar to > > devm_gpio_request() in linux/gpio.h : > > > > In linux/mutex.h, add a prototype for devm_mutex_init() when > > CONFIG_DEBUG_MUTEXES is defined and an empty static inline otherwise. > > Then define devm_mutex_init() in kernel/locking/mutex-debug.c > > Yes, this would be almost perfect decision. BTW just as in linux/gpio.h > we wouldn't have to include whole "linux/device.h" into mutex.h, only > add forward declaration of struct device; > > > Wouldn't that work ? No. It will require inclusion of device.h (which is a twisted hell from the header perspective) into mutex.h. Completely unappreciated move. --=20 With Best Regards, Andy Shevchenko