Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2213447rwb; Sun, 2 Oct 2022 18:18:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM654Xy2/O1IK3EM7P5TXaD4sT3g8952IrEAoXV56wGpih3qiiSKKByJ/eyrwGUolxU4NNW/ X-Received: by 2002:aa7:8887:0:b0:561:6985:1d02 with SMTP id z7-20020aa78887000000b0056169851d02mr2856834pfe.82.1664759904982; Sun, 02 Oct 2022 18:18:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664759904; cv=none; d=google.com; s=arc-20160816; b=uuXRQrP+jKod2axFVK1COQJkdWopl85VBUcPYkOqSQXqExQmhkutxkoIy0TRzsATOK br9eMk3IfSi8FAydvwChfiqlhgSBFE8KOT+IYc/Scz+4LAHlhfxxEWMM4IWEN/5X6hAs jpce8anPfvzvP6fie18+5fJ03Jqqopsk6uRBM/nnpaiwRjnokvFwfImJHkpiFvE9ISoM GNTtxv8+pzMuDS2L65kLCllk7pL1BNrjlOdmfI2zS2wnnLiVuDEo1MDdz5oT2AhoqAzw inFKEKJgC6VIMEpkfx1kGOfp0k6TZ5zQ0xbzheA5Qfik63gSkhX1zBJHWwTy3l+OBBuf 8gWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=AApPItY12rW1fRwzvRixw7DXPg/eFW6U6K8IgHIITM4=; b=iIC5JxL8j3IbMtFPXSgs9r7XyPnZes9Gd3ch26JJROaoR9UuSO6vxKyLQagVIGHKyI lu82gzxENhyERKBxTbQbAmo4bLueIZLfjoTajt6Qknq5Jtmdpt3OH+fTES9X0SRPdHoJ VZU2l7MHuAD6dUdwH7iMYfGo+1F5t+NeQcfi41T3gkC/og4uKarMyyAVVLIM6Tc/xkMv Bpd7Mz1WSPb/l1kNJPEEGGNTbMh0z9ijz88ciwWZRPJ0qsjgZU5mz2y803jIinoFJ1r/ HpGXTBA8dSdcqQZXLlhHgff519ovDn21LP8c4E62h0FqRZ/9qVgFI/+bzF5V2kEGsU2R wzVg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e63-20020a636942000000b00430980f4c69si8785176pgc.872.2022.10.02.18.18.13; Sun, 02 Oct 2022 18:18:24 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229493AbiJBX7N convert rfc822-to-8bit (ORCPT + 99 others); Sun, 2 Oct 2022 19:59:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbiJBX7L (ORCPT ); Sun, 2 Oct 2022 19:59:11 -0400 Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF1BC1CB39; Sun, 2 Oct 2022 16:59:10 -0700 (PDT) Received: from omf05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0CDBB1C5CFB; Sun, 2 Oct 2022 23:59:08 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf05.hostedemail.com (Postfix) with ESMTPA id B1DD92000E; Sun, 2 Oct 2022 23:58:43 +0000 (UTC) Message-ID: Subject: Re: [PATCH v4 10/14] gunyah: sysfs: Add node to describe supported features From: Joe Perches To: Jeff Johnson , Elliot Berman , Bjorn Andersson Cc: Murali Nalajala , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Andy Gross , Dmitry Baryshkov , Jassi Brar , linux-arm-kernel@lists.infradead.org, Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , Will Deacon , Catalin Marinas , Arnd Bergmann , Greg Kroah-Hartman , devicetree@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Date: Sun, 02 Oct 2022 16:58:59 -0700 In-Reply-To: <1f599b97-9242-3844-4372-1610948f4baf@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> <20220928195633.2348848-11-quic_eberman@quicinc.com> <3c02aad6d8bde70964b403a3cb8004de969becc6.camel@perches.com> <1f599b97-9242-3844-4372-1610948f4baf@quicinc.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Rspamd-Queue-Id: B1DD92000E X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,FORGED_SPF_HELO, KHOP_HELO_FCRDNS,SPF_HELO_PASS,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Stat-Signature: bxo4uofuiuh44az86fsxqtaeyj75n91x X-Rspamd-Server: rspamout07 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1/LAwYOxWYuUHOFlw80rjQndZ2p3aMK5A8= X-HE-Tag: 1664755123-277924 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 On Sun, 2022-10-02 at 16:30 -0700, Jeff Johnson wrote: > On 9/29/2022 12:36 AM, Joe Perches wrote: > > On Wed, 2022-09-28 at 12:56 -0700, Elliot Berman wrote: > > > Add a sysfs node to list the features that the Gunyah hypervisor and > > > Linux supports. For now, Linux support cspace (capability IDs) and > > > message queues, so only report those.. > > [] > > > diff --git a/drivers/virt/gunyah/sysfs.c b/drivers/virt/gunyah/sysfs.c > > [] > > > @@ -25,9 +25,24 @@ static ssize_t variant_show(struct kobject *kobj, struct kobj_attribute *attr, c > > > } > > > static struct kobj_attribute variant_attr = __ATTR_RO(variant); > > > > > > +static ssize_t features_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer) > > > +{ > > > + int len = 0; > > > + > > > + if (GH_IDENTIFY_PARTITION_CSPACE(gunyah_api.flags)) > > > + len += sysfs_emit_at(buffer, len, "cspace "); > > > + if (GH_IDENTIFY_MSGQUEUE(gunyah_api.flags)) > > > + len += sysfs_emit_at(buffer, len, "message-queue "); > > > + > > > + len += sysfs_emit_at(buffer, len, "\n"); > > > + return len; > > > +} > > > > It's generally nicer to avoid unnecessary output spaces. > > > > Perhaps: > > > > { > > int len = 0; > > > > if (GH_IDENTIFY_PARTITION_CSPACE(gunyah_api.flags)) > > len += sysfs_emit_at(buffer, len, "cspace"); > > if (GH_IDENTIFY_MSGQUEUE(gunyah_api.flags)) { > > if (len) > > len += sysfs_emit_at(buffer, len, " "); > > len += sysfs_emit_at(buffer, len, "message-queue"); > > } > > > > len += sysfs_emit_at(buffer, len, "\n"); > > > > return len; > > } > > > > that approach seems ok for 2 features, but imo doesn't scale for more. > I like the original code with one exception: > > if (GH_IDENTIFY_PARTITION_CSPACE(gunyah_api.flags)) > len += sysfs_emit_at(buffer, len, "cspace "); > if (GH_IDENTIFY_MSGQUEUE(gunyah_api.flags)) > len += sysfs_emit_at(buffer, len, "message-queue "); > > /* overwrite last trailing space */ > if (len) > len--; > > len += sysfs_emit_at(buffer, len, "\n"); > return len; > That's fine as long as every formatted output uses a trailing space. A trivial negative would be that the linker would generally not be able to deduplicate these output strings with trailing spaces across the entire codebase.