Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1545094pxv; Fri, 16 Jul 2021 11:38:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoIcI1HlP+wgOhPrlTsAtVcY/Tr8Xl9cwiVDhLaiAeTKdu18aqfBzcnwG1TgtO8H6s7m+N X-Received: by 2002:a17:906:86ce:: with SMTP id j14mr13036835ejy.152.1626460726503; Fri, 16 Jul 2021 11:38:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626460726; cv=none; d=google.com; s=arc-20160816; b=nbj+F8mc6jEUqrJH6DmAiH0Ui+w8tIbvtCo9b4fmG8lk6NVuTNei88UAYLqLTVdZ7d Emn9UGLOrvA292Od3f7TyXO0mZEypSc4i62kf9YWMBPA53iKo/hfXI6BDznLMMp6q6Hb EG4WX1RXJ0t34wDNnnYV8zSl1OJdGVDJFOZgPe9RRgi65od24nRDl36lRtEjlaBZxTOx 1PwuIf5b5aKmEdmAUIUylJdRMDjJixgLVC2GkySnMnhEeb55rJI/eqHIDC0NyVJjrSU/ UkxiM/iQK/XR4nzojx3XMp7z6ZDW68k/IPT7nXL2CP+hS282k6eXvqp/N3BwnbeZxpZ9 l3TQ== 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:subject:cc:to:from:date; bh=0LA1ZJBXbz2YXjrAqTAC2kBLAc6DlKVZjzT+t9DlmBA=; b=kKiGNoblVHa5k4cHqxn9qcaxFnpC5X1EjYy+9qYgDNwQhiiKsofoVcWQcTzcintq4+ 8TiMn3rIaeZGGal8Eo+c7zfFT2eqVcjaPlMZVAZJgdRKG7MEyYBKvs9Zm30D3UJrA28s yzrktIxzyel1E+SOhZqogH4q8k6ke7bHiuDC4U0bOxmHnb9fkFtOXPMxHAbqo92XiZM6 qgVjvJLcCKVUPmkcaX+OYV8z7dbj++7cOzHuvQz6yk90xLHWmI+MLB7laclR5udRgPJc 2Z715j5M3HbaabmsApw5MV7icgUwBbiqzhF16CoJQ47dUEFPYAyOVdqsNmxAgR8UUgxR Mv8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g13si12010483eds.419.2021.07.16.11.38.23; Fri, 16 Jul 2021 11:38:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230018AbhGPSkD (ORCPT + 99 others); Fri, 16 Jul 2021 14:40:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:51504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbhGPSkD (ORCPT ); Fri, 16 Jul 2021 14:40:03 -0400 Received: from oasis.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B13606115B; Fri, 16 Jul 2021 18:37:07 +0000 (UTC) Date: Fri, 16 Jul 2021 14:37:05 -0400 From: Steven Rostedt To: Linus Torvalds Cc: LKML , Ingo Molnar , Andrew Morton , Chuck Lever Subject: Re: [GIT PULL] tracing: histogram fix and take 2 on the __string_len() marcros Message-ID: <20210716143705.56001390@oasis.local.home> In-Reply-To: References: <20210715215753.4a314e97@rorschach.local.home> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 16 Jul 2021 11:11:38 -0700 Linus Torvalds wrote: > On Thu, Jul 15, 2021 at 6:57 PM Steven Rostedt wrote: > > > > tracing: One fix in the histogram code and another take at the __string_len() macro > > What part of "strncpy()" is garbage did I not make clear? So how do you want this implemented? #define __assign_str_len(dst, src, len) \ do { \ strscpy(__get_str(dst), (src) ? (const char *)(src) : "(null)", len); \ __get_str(dst)[len] = '\0'; \ } while(0) I could even do: #define __assign_str_len(dst, src, len) \ do { \ if (!src && len > 6) \ len = 6; \ memcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)", len); \ __get_str(dst)[len] = '\0'; \ } while(0) Which would work just as well, although I had to account if len is greater than "(null)". Which should never happen, but I have it there, because I copied the code from the __string() version which uses strlen() and that would break if a null is passed in (which in rare cases happen). But it would actually be a bug to use __string_len() in a place that can take a NULL, unless len was zero. Not sure how the above is any different than using strncpy(). Again, src is a string without a '\0'. What I don't understand is how strscpy() is any better than strncpy() in this situation? As I replied to you last time, the dst is created by allocating 'len + 1' on the ring buffer, and len is to be no greater than the number of characters in src. The only purpose to use this is to either truncate a string, or to pass in a string that was read from a memory location that does not have a terminating '\0' in it, but you know the length of the string. If you have a normal string, simply use the __string() which uses strlen() to calculate the required space. It's basically this: dst = malloc(len + 1); memcpy(dst, src, len); dst[len] = '\0'; "strncpy() is garbage" does not compute to me in the above usage. -- Steve