Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4115198pxk; Tue, 29 Sep 2020 15:01:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNJMrmjjwx5UnGGQA8lIHuxAZyliCqc/vwCR6MRPdv9mOxq+1uvvOjGL6ENVYxLAZ9Hx52 X-Received: by 2002:a05:6402:64b:: with SMTP id u11mr5281068edx.147.1601416894639; Tue, 29 Sep 2020 15:01:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601416894; cv=none; d=google.com; s=arc-20160816; b=pAzUx2dpXMI9gm61oi9XXc5Gesto+nbQGhvnrVT1WCYeYaVFKm5L+9nGxAkEEiSWKl C9FOF1T1r6UMIcIMgZip5ZSboej0uz4zCU3B20TakXvELueGxE/8Pqs9Dxpcb4426lcG Ugzt+uvqbkMezxpaJhqR4LVP/I7lDy/aTtIA3A+sBsNy5EKrzvBhIAi8xzQbcKbTXsqW MRI357n2H0ttK27qZq5xU9/NKCfOyoWRmpx22d2Bo67Lm93dE5wj1HnOFHDCJq4D+ssd YbKGjQYJEXFIhgI9MwskaiCVQM9Q24ZgE5yhPsx6b0iBO8yttODWqGNyWiJkbQ9H6qba jjpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=0/OJ+hGul9V2Z4KJ9/Icrdv537pi3bbPLRFN0e0T6pk=; b=Yob3nYgn9y1AipxyoB98CClaItQ74HTygplDlvw0W0iByyLx9QVI4RtIvdGz6L2YkN ++FN6G13LVlV8/hrAkCcpXdgY05Kk/voOjOMgmyWx8uKSWdLzbqlr577wBYfUbaGM84T HhPbpQ7pX0PHDVrXv69TduUBJBJtJVGObFhi/8/lpz7KVUeQ5ZiyrALOqHFEkKvxOxHg HEC5G0obABEEyB2Kbt6Muxs/lVGvXq7UEBGcf5J9sQcog42n7PummQP3dCT0trr9efde JmSLEeLfo0dqsP8qoyzRm7kxiXf8vJM5qxF/NrsETPUqPomlM64gQsUz6gFrZ2Eib1UW hrbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="UZdtN8Y/"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z4si3327975ejf.594.2020.09.29.15.01.11; Tue, 29 Sep 2020 15:01:34 -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; dkim=pass header.i=@google.com header.s=20161025 header.b="UZdtN8Y/"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728587AbgI2V5V (ORCPT + 99 others); Tue, 29 Sep 2020 17:57:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728199AbgI2V5S (ORCPT ); Tue, 29 Sep 2020 17:57:18 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98B35C061755 for ; Tue, 29 Sep 2020 14:57:16 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id s31so5030806pga.7 for ; Tue, 29 Sep 2020 14:57:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0/OJ+hGul9V2Z4KJ9/Icrdv537pi3bbPLRFN0e0T6pk=; b=UZdtN8Y/tGfQ/ZGzeOHsdwamEaty92m/di0YmBL75oxm6d3+rB/8/zyz1YDULbBVHR dihKbPiWMG9bvNU7FVgSQAGmV3es5ez69hUVkSc3lPx0Bv5Mh2xI3C0iaXfW+HVzkzZr w/h1MCrpvNZ9gRi4Z+1cweDfdT2UlNgS3r9JX+sR84HxBqm6rU2vLW+LhHaGfUVoQfPt yDY+YiSsLQpT/UsBkUYFraIe3ZbE1k1e62DKXCAc8x6VnAYuaMhAXGz9d9c9BvQsY2Kn G4fGkjUIYuggjBJ0zjKaBU8sDJ/MrAIhN1fYjCefHJmammumqMLQE4pxl+xVTiyHGHoU S1lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0/OJ+hGul9V2Z4KJ9/Icrdv537pi3bbPLRFN0e0T6pk=; b=naL4F9USvzYiRB/+40RDWmQkHtSZdTcJjnIhIesKinFdvO9rhbaq2ePA9Ci8BZtqvw UwpcOjkj7YKXX7I8vz8sTNjjbQQZZvXd2GH4GRrBFuDeGDY1npmh3cEmeb4aMVQrBCKW QtlVGj4M1x6wvqg/xPcpfX8tgQsBZXXfpMF2RDKCTOgpiXANvpmqQA+IOqy50Oqn7yek unkEv5lkAvDQ1ealayJmr5tpctXpNOncTzNDPnh5GxMQkz/hE2P0E86Fr2uLARdU/DlL Bybmos88vFxJ99hxMLnBhcT6QXMCwYACbMAHkXLq3iLi9GPk/z4NXn9eZhpfEI1peJ2p /feQ== X-Gm-Message-State: AOAM533S6M4CiezaXTZHR6YE9gJ5eww6izUPOnNIsP+xkR0GYElXYbhF ad7VEJT5CAqwAT90UrA8xlYjsjq8vMK6+DZcqEZ8Bg== X-Received: by 2002:a17:902:544:b029:d2:6379:a892 with SMTP id 62-20020a1709020544b02900d26379a892mr6646545plf.53.1601416635987; Tue, 29 Sep 2020 14:57:15 -0700 (PDT) MIME-Version: 1.0 References: <834e9060c2e7e3272e25d8bfc6e7566639c18aa9.1601410890.git.zanussi@kernel.org> In-Reply-To: <834e9060c2e7e3272e25d8bfc6e7566639c18aa9.1601410890.git.zanussi@kernel.org> From: Axel Rasmussen Date: Tue, 29 Sep 2020 14:56:39 -0700 Message-ID: Subject: Re: [PATCH 2/3] tracing: Fix parse_synth_field() error handling To: Tom Zanussi Cc: Steven Rostedt , Masami Hiramatsu , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 29, 2020 at 1:33 PM Tom Zanussi wrote: > > synth_field_size() returns either the size or an error. However, the > code assigns the return val to ssize_t which is unsigned, and then > tests whether it's less than 0, which it isn't so discards the error. I think the patch is correct, but the commit message is not. field->size is a size_t (unsigned), not an ssize_t (signed). I think this should say instead something like: synth_field_size() returns either a positive size or an error (zero or a negative value). However, the existing code assumes the only error value is 0. It doesn't handle negative error codes, as it assigns directly to field->size (a size_t; unsigned), thereby interpreting the error code as a valid size instead. > > Do the test before assignment to field->size. > > Signed-off-by: Tom Zanussi > --- > kernel/trace/trace_events_synth.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c > index a9cd7793f7ea..6e7282c7b530 100644 > --- a/kernel/trace/trace_events_synth.c > +++ b/kernel/trace/trace_events_synth.c > @@ -465,6 +465,7 @@ static struct synth_field *parse_synth_field(int argc, const char **argv, > struct synth_field *field; > const char *prefix = NULL, *field_type = argv[0], *field_name, *array; > int len, ret = 0; > + int size; Why not make this an ssize_t > > if (field_type[0] == ';') > field_type++; > @@ -520,11 +521,12 @@ static struct synth_field *parse_synth_field(int argc, const char **argv, > field->type[len - 1] = '\0'; > } > > - field->size = synth_field_size(field->type); > - if (!field->size) { > + size = synth_field_size(field->type); > + if (size < 0) { > ret = -EINVAL; > goto free; > } > + field->size = size; > > if (synth_field_is_string(field->type)) > field->is_string = true; > -- > 2.17.1 >