Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2261348rwd; Tue, 13 Jun 2023 23:43:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ62cSzpJmF6FbbprFzgy/NDy3RxqWuk8xmDWlUOV3n4tm9b/fOmwqryLWvsBPbqQqFPRzfY X-Received: by 2002:a05:620a:4bcc:b0:75e:c23f:82ef with SMTP id sw12-20020a05620a4bcc00b0075ec23f82efmr12982763qkn.67.1686724989798; Tue, 13 Jun 2023 23:43:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686724989; cv=none; d=google.com; s=arc-20160816; b=txb3C0Rwr6aOQgfrptgZCA1rDLDWeSFB2hpZ1DgA4aFQ+wFP6+YfKTuzG9I52/vSeI 7bNR5JJuKTaBuNtNXid6tuAyjJZjNizZkK/byje9okPdzrv9gIl2cRkuXztzoSNSCEeS strs9432wE8v100FpzRQZO/SQIZ1E8oaE2sqFr5egGKUGirSx13h+0/bbxCtJl17V0nc g7/HxNsHvcqciLo1feGiMWuFWmvWSl8FLuFeXvZRbphYX1UBUXdf0sFt+GgS7JWJ6uxK wXbTIQDFt6A80Zc0u0t2U1ztb8HMUehw1Gpcn6dqHtlA3wu4AogisrFtIJTdRpCdQoml SyhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zxDjpsQsnHKyp+46A4IVR8UbFfLpDgOYCYup7v5oaqk=; b=BYj846hFHbtklThSDWg6Z2xUzx8GyVkd18ecLou6kqdkVrSFKygulQ+cFSGdb2gd7J VMmINnOMpz6epwWSQMW65HdMPrdkgu/FhPASeQDC06eZ8BTObEjAbbc4f5hjEITrWBbG kFxAgXHNAy2WDFSJWOnTQdOuvqGr+E2eqYDY6JadmM+m7pqR5GnL2HzhZpltN5WSR0nc JvgKN2e9+r3d/LPC7wkMqW8hdlKroL6BpCgxS1sxKKF+VyvfzBUousfYDr6vEubXoEz/ QgxL++knrWGA0A4zd5lP9WsN+wQ2PRfNTR4zzezBJbllUPyceisEjmPpeq/1EoWCiMik XO3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=W3Gfs6pV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a186-20020a624dc3000000b00665c1447b66si3172442pfb.405.2023.06.13.23.42.57; Tue, 13 Jun 2023 23:43:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=W3Gfs6pV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243214AbjFNGbP (ORCPT + 99 others); Wed, 14 Jun 2023 02:31:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243216AbjFNGan (ORCPT ); Wed, 14 Jun 2023 02:30:43 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 440CC213F for ; Tue, 13 Jun 2023 23:30:22 -0700 (PDT) X-GND-Sasl: miquel.raynal@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1686724221; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zxDjpsQsnHKyp+46A4IVR8UbFfLpDgOYCYup7v5oaqk=; b=W3Gfs6pVbddjBLmdgT5NvK6nsbXjzsjABQxhtvuX0NESqymciSDiL3+HcVhAaWEIaQh04w SlZXRj9DYw45Ek4PTgZWMb6HPM2nnZ7F0gVaqkinmaYULieA+doinqMaMfefDqZ9qv5vtj 1u6UeZ8aUF2cdCUtcizm5aJEkKQwhimJy3VgSjv5bZ2MSLkZWubUg+TN6QOlFTtIoWd1gg xWIMO6VeHqJhaXHwUJfGjRfczemlTfq64ixgAU4Q+Y/8goyaztUjtxz+YpxBY6gNgewhCg everkFlE9xeAQvFBsoOXHE2GIrO/MkeZx8NUv6HUT23wWV+SizyPTZ60IB0ZVw== X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id D5174FF80B; Wed, 14 Jun 2023 06:30:20 +0000 (UTC) From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , "Rafael J . Wysocki" , , Thomas Petazzoni , Luka Perkov , Robert Marko , Miquel Raynal Subject: [PATCH v4 2/4] sysfs: Skip empty folders creation Date: Wed, 14 Jun 2023 08:30:16 +0200 Message-Id: <20230614063018.2419043-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230614063018.2419043-1-miquel.raynal@bootlin.com> References: <20230614063018.2419043-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Most sysfs attributes are statically defined, the goal with this design being to be able to move all the filesystem description into read-only memory. Anyway, it may be relevant in some cases to populate attributes at run time. This leads to situation where an attribute may or may not be present depending on conditions which are not known at compile time, up to the point where no attribute at all gets added in a folder which then becomes "sometimes" empty. Problem is, providing an attribute group with a name and without .[bin_]attrs members will be loudly refused by the core, leading in most cases to a device registration failure. The simple way to support such situation right now is to dynamically allocate an empty attribute array, which is: * a (small) waste of space * a waste of time * disturbing, to say the least, as an empty sysfs folder will be created anyway. Another (even worse) possibility would be to dynamically overwrite a member of the attribute_group list, hopefully the last, which is also supposed to remain in the read-only section. In order to avoid these hackish situations, while still giving a little bit of flexibility, we might just check the validity of the .[bin_]attrs list and, if empty, just skip the attribute group creation instead of failing. This way, developers will not be tempted to workaround the core with useless allocations or strange writes on supposedly read-only structures. The content of the WARN() message is kept but turned into a debug message in order to help developers understanding why their sysfs folders might now silently fail to be created. Signed-off-by: Miquel Raynal --- fs/sysfs/group.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 990309132c93..138676463336 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -118,11 +118,13 @@ static int internal_create_group(struct kobject *kobj, int update, /* Updates may happen before the object has been instantiated */ if (unlikely(update && !kobj->sd)) return -EINVAL; + if (!grp->attrs && !grp->bin_attrs) { - WARN(1, "sysfs: (bin_)attrs not set by subsystem for group: %s/%s\n", - kobj->name, grp->name ?: ""); - return -EINVAL; + pr_debug("sysfs: (bin_)attrs not set by subsystem for group: %s/%s, skipping\n", + kobj->name, grp->name ?: ""); + return 0; } + kobject_get_ownership(kobj, &uid, &gid); if (grp->name) { if (update) { -- 2.34.1