Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5372622rwl; Sun, 8 Jan 2023 13:58:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXs5Y7QAhfEy6YwF62JUEY6HrFbYRslMK7LmVgUGvDL5V3f5EfvX+0AX23HBiklj79akSoW2 X-Received: by 2002:a05:6402:538d:b0:487:2ce6:2b80 with SMTP id ew13-20020a056402538d00b004872ce62b80mr38593111edb.8.1673215134097; Sun, 08 Jan 2023 13:58:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673215134; cv=none; d=google.com; s=arc-20160816; b=DFIpOtAdiCvRukvBlYsryYlDwcyYT92238iUlpfRe7v32pwx6DSEDWHutGRocPRZam B3QlZHdRKZ0n+BMdN0GRhSj9+bsUDV/cAUBNehn68zcYpyMbXogLZjMiWBtpuD77U5sH KM8r26Jrwm9dVHfKKKvuY19dLONaf+aT3mdpBDhZGUbv5mrrA5IhfEs2lXxh2lnhEXXC ffh5vQaYF8eZSFefmVchD8ilIVY88iGotnf+yE/5flP9ITsPTlBMRpHDB4yRhv4Rd+i7 CRHdkX+3+Lt5ClNg6fs1j5yR7WoGR1yT+rpTshjMlxRr8p1wpyZsnEUX8TobKSC7ggqD qAoQ== 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=0oxxNSDrYibg4LJTbIYyi1h8URavYFNM8imNVvdjezM=; b=tyu7fGksfnChm/H+O1ANMTT2G0mcxbaS5RwZXhimP3nFWbIvRsLTCcdHzYGN7pkTj8 u0iKrXtoPPj15c2HiSjyQAknfjwso6GueHuQT8LdXtiEyuSgmzHobLhqtiEufLRbOM0t pjiLuQLbh0Cv4+S4L3reQ0NhwfwUX2DQ6cyI4zURXsGcQo2J0f4tXbSW5nsBwxhTqpL3 eA4kBXdRypgFROQe+HpBKF417Za1nPC7bFzmL3uChN8fmCxK+kDaMHZVOhkyCaPcWaKB hMfG8eeMuMlBONzD4Lh+Q/YGoHn4c9qYL0pKoLvy2fsU1GCjU9ecd5UtBO5rDcXrG676 /3/g== 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 t23-20020aa7d717000000b004534c6c4bd7si7018474edq.433.2023.01.08.13.58.42; Sun, 08 Jan 2023 13:58:54 -0800 (PST) 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 S230334AbjAHVWd (ORCPT + 51 others); Sun, 8 Jan 2023 16:22:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231292AbjAHVWa (ORCPT ); Sun, 8 Jan 2023 16:22:30 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6333E017; Sun, 8 Jan 2023 13:22:28 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 76F15B80C03; Sun, 8 Jan 2023 21:22:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74F4BC433EF; Sun, 8 Jan 2023 21:22:25 +0000 (UTC) Date: Sun, 8 Jan 2023 16:22:22 -0500 From: Steven Rostedt To: Quanfa Fu Cc: rostedt@goodmis.or, mhiramat@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH] tracing/eprobe: Replace kzalloc with kmalloc Message-ID: <20230108162222.146d136f@rorschach.local.home> In-Reply-To: <20230107034335.1154374-1-quanfafu@gmail.com> References: <20230107034335.1154374-1-quanfafu@gmail.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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 On Sat, 7 Jan 2023 11:43:35 +0800 Quanfa Fu wrote: > Since this memory will be filled soon below, I feel that there is kzalloc() is also used as a safety measure to make sure nothing is accidentally exposed. I rather keep it for safety. Just because it doesn't need to be here doesn't mean it should be removed. There is no benefit to making this kmalloc(), as this is far from a fast path. > no need for a memory of all zeros here. 'snprintf' does not return > negative num according to ISO C99, so I feel that no judgment is > needed here. Also, it's best to remove "feelings" from change logs. Code updates are not made due to how one feels about something (at least it shouldn't be), but about having technical reasons for doing so. I do agree there's no reason to check snprintf() from returning negative, as looking at its implementation, there is no negative return. Thus, the change log should be: "No need to check for negative return value from snprintf() as the code does not return negative values." > > No functional change intended. And this does have functional changes. If the output of a compiler is different for a function, then that's a functional change. What we consider non functional changes is if functions get moved around, or possibly code in a function is moved into a helper function where the compiler *should* end up with the same assembly. Changing what malloc is called is definitely a functional change. > > Signed-off-by: Quanfa Fu > --- > kernel/trace/trace_eprobe.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c > index 352b65e2b910..cd1d271a74e7 100644 > --- a/kernel/trace/trace_eprobe.c > +++ b/kernel/trace/trace_eprobe.c > @@ -917,15 +917,13 @@ static int trace_eprobe_parse_filter(struct trace_eprobe *ep, int argc, const ch > for (i = 0; i < argc; i++) > len += strlen(argv[i]) + 1; > > - ep->filter_str = kzalloc(len, GFP_KERNEL); > + ep->filter_str = kmalloc(len, GFP_KERNEL); > if (!ep->filter_str) > return -ENOMEM; > > p = ep->filter_str; > for (i = 0; i < argc; i++) { > ret = snprintf(p, len, "%s ", argv[i]); I wonder if this should be a strncat() instead? > - if (ret < 0) > - goto error; > if (ret > len) { > ret = -E2BIG; > goto error; for (i = 0; i < arcc, i++) strncat(ep->filter_str, argv[i], len); I mean, before this code we have that loop already determining what len is, do we really need to check if it is going to be -E2BIG? -- Steve