Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5627772rdb; Wed, 13 Dec 2023 14:38:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IENbbdCChV4JveVG59H31v7Y1tqxy4AwNknSm59yiiqe5lgjckrcBt1Qc+DMFHw+OwyedRv X-Received: by 2002:a05:6808:f10:b0:3ae:156f:d312 with SMTP id m16-20020a0568080f1000b003ae156fd312mr12314450oiw.34.1702507137670; Wed, 13 Dec 2023 14:38:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702507137; cv=none; d=google.com; s=arc-20160816; b=lD3OVKf9yBtdfqnO3mNPjPNUx/6rPv9lZheEa7NDjVNp97wV59uKDgFAo5Wobw2HFG xj8gWT1RDLhgx/s9iRVnHJuBazVav4inhFYBHiexCdn7cHo2SE+sP1ZiPmQCJD+Yrlkm JWEIS4hFx+DbZtMCrmD8a+7pgNzZ6TWvLV7TkGguGmdxxVsJW6xgmH7mv8nrYrfDBmcG AbrRLh3pRsMyaDxGf7n1JHhr0rKUzQi5IWY6vmrkrxwIbWuzGKiJT7pUPj6VSlnsXea9 9GLfaX2lFGmyKIH8WnfUOX+do0zaxWJe6pmlzrXXxK8lxtqmnMHo0OWI4pZeBxeK8S94 D/PA== 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=HLWuIS891/i8mk8Po2VW+0HfMFW0IVIkJ746lLbBUXQ=; fh=ClqKaT3H8A5zcmq20YJa4NR5n6NiKKJYvEiTqN7BbsE=; b=Kg+G4IptxCzmKuMw110oaig3Jy8JUCi8LGARBCCIWgllObfKHQSNg+a8PwN0nh5Qzp Li3vcYGCCdDVAxwuk4KYHxOgG6hoOJZMJ9Kos0OQWukDoLTs2vXen5XLXgfbmaVoStEO Cp1oIOUvQ3vPv84V9GMGYth+lMsxtEZvJf96UNIUeRR5lyAvNiF5YUvXeNO/NCMpqMjX LbyRr7Lc4vqwqpK7mV09DDEGdzofCPZsiGaV8Y86MX4cHThJQoi+OQX8VPTrEvkIfZqd o/nSNkWvC4r9HIkyQQhWYkHaj6WWGmewG7kXzxHSnEWpmpPORmIGSJKWSEjx984VRyVx pn0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QOg3anvL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id by26-20020a056a02059a00b005c6832282f7si10589905pgb.304.2023.12.13.14.38.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 14:38:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QOg3anvL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 9A23F80309E6; Wed, 13 Dec 2023 14:38:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442797AbjLMWip (ORCPT + 99 others); Wed, 13 Dec 2023 17:38:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbjLMWio (ORCPT ); Wed, 13 Dec 2023 17:38:44 -0500 Received: from mail-vk1-xa36.google.com (mail-vk1-xa36.google.com [IPv6:2607:f8b0:4864:20::a36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8460ACD; Wed, 13 Dec 2023 14:38:50 -0800 (PST) Received: by mail-vk1-xa36.google.com with SMTP id 71dfb90a1353d-4b2cf7ce00bso2032331e0c.2; Wed, 13 Dec 2023 14:38:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702507129; x=1703111929; 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=HLWuIS891/i8mk8Po2VW+0HfMFW0IVIkJ746lLbBUXQ=; b=QOg3anvLdafamjEd6i0gvTGuSs+YszTktNnZEaPoG1pA5TZygEOPIZbUjPJcOPZUAY MpHHAWrHFnuxBG2Q3oS+/RZ7bQdLtLIeYAqOWS4do5OuGDgGarKnkOcneeFiT51VCCO/ eLSx4L98pwAR+4hCse02WUDb5S6PFWq19YBk3U/3wDEsrVKmm+uznaXM2hQq7JahU63s +6GTMrGOl6yAgFlMr6Ttl6Y1kq2PIaH6uP+tOh2JojyjOtlgfV8o39g3XFUanOXuvd5j c38Nv68B4t/UMMDMMWt5O1FVPjxMFCE0ihAcDoaApw5A0xLXeptSxBSAWho0VrYEq2lD it+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702507129; x=1703111929; 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=HLWuIS891/i8mk8Po2VW+0HfMFW0IVIkJ746lLbBUXQ=; b=RGKYdtL9B+JEeWVWE5c/hb2bSXsOn+DYOT4gHJVpZ63A7QBCXY+w/xetDcuMTsS4f1 RnDxSJCiQYJD44vLQHxgC166amPXUJf3OGwykR79OLD5ajOAoTLRFU9ETqkCYl/mvF0A a10vwlVKrQ9AupxVyEmQsm5a8BR6WoJjywWr0R723iBd/ozhlX/TbsK3V3nwu4b4YP3/ s9IDzjWnD9B6EA5Wt/vCcj703TNdejsW1CUnw1Sjj0nnXIocTJyW9ga5kQTzxrd/LT5r t9XSnJxFG//C5N9yh64mMvSHj2CY9/jETOm4rpJbDf3GA5jRDqwOkCbkiHOjz0/TmONT Dsmw== X-Gm-Message-State: AOJu0YxSwyHn15uluFL+8TqXHtCdm9wtOVeiB0wIDivh9KFEpfRMQTPt 8udfh2kHuPOss6AsaqRKny/7+RqAu5kO0GRofE6Nh1KtqDg= X-Received: by 2002:a05:6122:1699:b0:4ac:1423:1be9 with SMTP id 25-20020a056122169900b004ac14231be9mr8733380vkl.13.1702507129585; Wed, 13 Dec 2023 14:38:49 -0800 (PST) MIME-Version: 1.0 References: <20231213223020.2713164-1-gnstark@salutedevices.com> <20231213223020.2713164-4-gnstark@salutedevices.com> In-Reply-To: From: Andy Shevchenko Date: Thu, 14 Dec 2023 00:38:13 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 13 Dec 2023 14:38:56 -0800 (PST) On Thu, Dec 14, 2023 at 12:36=E2=80=AFAM Andy Shevchenko wrote: > 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 no= w > > 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 i= s detached. > > + * > > + * Returns: 0 on success or a negative error code on failure. > > + */ > > +static inline int devm_mutex_init(struct device *dev, struct mutex *lo= ck) > > +{ > > + 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... > #endif --=20 With Best Regards, Andy Shevchenko