From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 232841E7C38 for ; Thu, 24 Jul 2025 11:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.211.166.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753357669; cv=none; b=TpjwkQQb8dTWfONQDiU/tPiqwvDgHJwepkSxeq9BbM5L84hEdl0r45rpucbw9gKfTKlYLdjo7Cn135CajRzEafL7gVJgXEOAXCsTyl6xse+8dm8Edemn8GaGL+VdIt9qsT6230n7+NSuzoguPWcdeBUfjGXLku/F5fHvbhWFjuw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753357669; c=relaxed/simple; bh=xgs77wx0lM2xjLQDZNmkRKSFSgm61ftYEgfHt5CdHN8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CxiS4sU/eOJt+TwwV02zSQ7FaEFQfADdpn9lOzG1EksceOjoKVKZdGMr72MMyp4RnegaPDQQZiuv8cC6uV3EfbD6EgPv31X0JPwr93p6BNZlC/Gs7T0c+Bdbw3T43y0VAsTpfwao4FjVaFKNYUQMJP3BR4dt60Ic+SIu46Kdy3w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Nz4Ludj7; arc=none smtp.client-ip=140.211.166.136 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Nz4Ludj7" Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id B4D2B60FEC for ; Thu, 24 Jul 2025 11:47:47 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org X-Spam-Flag: NO X-Spam-Score: -8.092 X-Spam-Level: Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id Q3-wpw163ETj for ; Thu, 24 Jul 2025 11:47:47 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=198.175.65.15; helo=mgamail.intel.com; envelope-from=andriy.shevchenko@intel.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 0955360717 Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=none dis=none) header.from=intel.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 0955360717 Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Nz4Ludj7 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) by smtp3.osuosl.org (Postfix) with ESMTPS id 0955360717 for ; Thu, 24 Jul 2025 11:47:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1753357667; x=1784893667; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=xgs77wx0lM2xjLQDZNmkRKSFSgm61ftYEgfHt5CdHN8=; b=Nz4Ludj7N4BuQ4GN6Zv0rtyxlOJKV5y+VOg5HqePtAdrjc7n7rCnPljC Z1AyydO4ICdWQ3QB0GVrd0RdaVNWxt0zJQwiSBbNFs1xOPYMw5ArsYXF5 WWwcoyRLoD6/iva+A9KLtiNv9e3fgGeW7VFPit+9FgmBLT3T7xPxH80Uy tqasjh0wCAHtw+ixpo4ktHArXZo09NoOEqS5+gsAs2JPbCqkX/nxybljZ JU747sq9Q2xIggazQLMcrAOAMK2a6iVj5otfJyjP7EIjXnMPTwPIHIMrB 64DyzUPg8EIaIGFIfMkilnlDwwKnk5Yj/wEk8v82pTlkLS2aQlhurDzRF A==; X-CSE-ConnectionGUID: FJFsmkLWQ/SQIGZvwk6oew== X-CSE-MsgGUID: qfdxFpQUT/GfLdSss/3ytw== X-IronPort-AV: E=McAfee;i="6800,10657,11501"; a="59325232" X-IronPort-AV: E=Sophos;i="6.16,337,1744095600"; d="scan'208";a="59325232" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2025 04:47:37 -0700 X-CSE-ConnectionGUID: kvjP7398T1mxSOqTWcEF1Q== X-CSE-MsgGUID: xsRqIuZyT7mW5crc68TO9Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,337,1744095600"; d="scan'208";a="160175276" Received: from smile.fi.intel.com ([10.237.72.52]) by fmviesa006.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2025 04:47:34 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.98.2) (envelope-from ) id 1ueuQ7-00000000Yh7-1siL; Thu, 24 Jul 2025 14:47:31 +0300 Date: Thu, 24 Jul 2025 14:47:31 +0300 From: Andy Shevchenko To: Jonathan Cameron Cc: Akshay Bansod , Lorenzo Bianconi , David Lechner , Nuno =?iso-8859-1?Q?S=E1?= , Andy Shevchenko , linux-kernel-mentees@lists.linuxfoundation.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] iio: st_lsm6dsx: Replace scnprintf with sysfs_emit Message-ID: References: <20250723141359.11723-1-akbansd@gmail.com> <20250723164100.34e864d6@jic23-huawei> Precedence: bulk X-Mailing-List: linux-kernel-mentees@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250723164100.34e864d6@jic23-huawei> Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo On Wed, Jul 23, 2025 at 04:41:00PM +0100, Jonathan Cameron wrote: > On Wed, 23 Jul 2025 17:42:28 +0300 > Andy Shevchenko wrote: > > On Wed, Jul 23, 2025 at 07:43:59PM +0530, Akshay Bansod wrote: ... > > > fs_table = &hw->settings->fs_table[sensor->id]; > > > for (i = 0; i < fs_table->fs_len; i++) > > > - len += scnprintf(buf + len, PAGE_SIZE - len, "0.%09u ", > > > - fs_table->fs_avl[i].gain); > > > - buf[len - 1] = '\n'; > > > + len += sysfs_emit_at(buf, len, "0.%09u ", > > > + fs_table->fs_avl[i].gain); > > > + > > > + sysfs_emit_at(buf, len - 1, "\n"); > > > > Still looks a bit weird (while working). > > > > > return len; > > > > I deally we should have a helper doing all this under the hood for plenty of > > the (existing) users in the kernel. > > hmm I'm not sure generic is terribly easy I agree, I have some plans for %p specifier extension, but I was stuck with it and it in half-basked state in some of my local Git branches. > and I'd prefer this using the > read_avail callbacks that require the data in an array where ever possible. > Mind you that does the same print at len - 1 as this. Let's play. > Completely untested. > > for (i = 0; i < fs_table->fs_len; i++) > len += sysfs_emit_at(buf, len, "0x%09u%c", > fs_table->fs_avl[i].gain, > ((i == fs_table->fs_len - 1) ? '\n', ' ')); > > better? Without extra parentheses this makes the job. > It's definitely not more readable than the above, but it does avoid the write > to len - 1. > > > In any case, I leave this change to others to comment, I don't object pushing > > it in this form, either way len - 1 is simply weird. -- With Best Regards, Andy Shevchenko