Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5627135rdb; Wed, 13 Dec 2023 14:37:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGabgyga/LQnyoTXKLrcxHJpJE5JN3LLwgO11mZZmVuWv0y7/MDda3FTGYWaX6mFtrU5z6w X-Received: by 2002:a05:6359:29d:b0:170:17eb:1df with SMTP id ek29-20020a056359029d00b0017017eb01dfmr5276921rwb.34.1702507039127; Wed, 13 Dec 2023 14:37:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702507039; cv=none; d=google.com; s=arc-20160816; b=rQUJrjLFn/9w8jZNPKEwU7n5n3FK9cW6B46PNGd0wgCMdeNZMGTPwkzAxlH1/wEmPr FpNU1LXatgxpVugw2YXi3tTfseGf7bK0qP35fjQZ70Voz+wOj798/QCM72CiLnRZaPO2 gGqw0mB2ZxDT7dgBQB4Jx4ATF1W2g+cxO8Edu4Zn68dc4/r5XT+XgNQ8+AXCJQNr/th3 Z2FGQbE42+wl6F1QVNcodxUQHLhEnQsXOi49ZWks+mDYlgAzf5tJP5j2KftcaOA/0o8z ptCpzowyZofG7LKQiN6VQv0unBnleQc5wCcGEe5AJlHJGf1jSxziwAgWNbcTamZ+JaDi KSHQ== 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=YhslwT3u/DM8BEIb5CNvkmOQPz2c8s+oUi5ecuMmZqY=; fh=ClqKaT3H8A5zcmq20YJa4NR5n6NiKKJYvEiTqN7BbsE=; b=oHAAngP6OJi8NlkGWS36pNAEN51sO46O9bgcM4OE4u8r1hZT86NC7xVcDDG7pIlFAl B5W2pbnIx0gSPQc0APokGSlDq78Nn+5A4EaM5gVbgRkXCYNc+HGU+6O5SqrBY4DDAE+X qTsxZY3vcPhbBmfiMUAol2VRfGOWEHDqbNvoUX5YC78/xwgErPPljH1sGtludDozw/6V 8w3EdVV6LLeJHXf+SUdkGJH/bS0lcK81tlSRCTrfjcbPsD+qPDMz3YVAsX0C5by93wXS bqf/MZk5ZYMhN2QiUCFH5PwC7qAYyLK5vZL29++rn07/0NqeXE/tPBCTVNEcVnxcITsR vfLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="F/udJqYg"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id ca13-20020a17090af30d00b0028ae729ce29si1581663pjb.81.2023.12.13.14.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 14:37:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="F/udJqYg"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 9AF82802A02B; Wed, 13 Dec 2023 14:37:16 -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 S229913AbjLMWhD (ORCPT + 99 others); Wed, 13 Dec 2023 17:37:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbjLMWhC (ORCPT ); Wed, 13 Dec 2023 17:37:02 -0500 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF1ABB7; Wed, 13 Dec 2023 14:37:08 -0800 (PST) Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-67ef9c6745eso6598076d6.1; Wed, 13 Dec 2023 14:37:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702507028; x=1703111828; 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=YhslwT3u/DM8BEIb5CNvkmOQPz2c8s+oUi5ecuMmZqY=; b=F/udJqYgCzCXgAh7y9VkrRAG7uVjrykp9ycw4BvTN+czBVk6BflLx8Wz5lhs7bGouT 4Wz3bZf0RTNzAKZYaSaH5lgc+gASML2Bk3V3nmL/q43AJMpzPueIVCVxRyyg8xvT98EK tuZtEYz5/oeppXauyXGbptwLcjVezrssAbeVbLs2UUMe/0c4Z6l10bdAC36hDH0rqYXd kOp4/uzpscZmDonlmLQn0blPJ9GLdq2zWkkAkbNpSh9RRpPFptOlhoB4/gVz6T/jhEQb ZmpPxUACIypLkhrmi+NeBeJaB8a3SZ3wgilRkmywVELG44pdUCwMLsZ8kyROZKfqprio 8Pow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702507028; x=1703111828; 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=YhslwT3u/DM8BEIb5CNvkmOQPz2c8s+oUi5ecuMmZqY=; b=EjWWNR37MYZc0M3nk4ioTCU0EaItlBRKGtA5WHthghyht3tDpd+U95I/si/nR0gQbf o++jMIoWDrChj60Ofxk73vQimAiloL5stmnhTb9q2d2uHpiyYl5cVqFVIAvN6mf7BUwp gD1FRSHPQpC/DaccPHOwbjMmXzuOQ+OQDVbNHYVujaKww/DxeXbB60xENl2rYOi2TPuY mRLY3F0ECLpl2hFxFwCq69tycRL4Dl1shz8Kft9rXaT/qSZQKw62y9PARaY71DZCQGXl csumcV0zHTReJS6b+ngbWBbb0YAvL7czd+szuOgoXZC81EP0bYnAtWIANSB/OscFUhDE 7ZGg== X-Gm-Message-State: AOJu0Yzu9TVLem/Ooh9ulqJdX9NVd9NZneLGBqIWDON54tCzqyIDUGMo sgBB4iNjKlOHc1w52RuoM8OfT9+N3QbRbR4HGRpTJGAtg+N5uw== X-Received: by 2002:a0c:c48b:0:b0:67a:a721:82f1 with SMTP id u11-20020a0cc48b000000b0067aa72182f1mr8302603qvi.75.1702507027837; Wed, 13 Dec 2023 14:37:07 -0800 (PST) MIME-Version: 1.0 References: <20231213223020.2713164-1-gnstark@salutedevices.com> <20231213223020.2713164-4-gnstark@salutedevices.com> In-Reply-To: <20231213223020.2713164-4-gnstark@salutedevices.com> From: Andy Shevchenko Date: Thu, 14 Dec 2023 00:36:31 +0200 Message-ID: Subject: Re: [PATCH v3 03/11] devm-helpers: introduce devm_mutex_init To: George Stark Cc: 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, 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 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 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, 13 Dec 2023 14:37:16 -0800 (PST) On Thu, Dec 14, 2023 at 12:30=E2=80=AFAM 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) #endif --=20 With Best Regards, Andy Shevchenko