From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 806F7318EE3 for ; Thu, 22 Jan 2026 09:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769075764; cv=none; b=YCGMe5IuxRC0EWl2fv/HBZFLw/arkyx9/TW4pebNX9X/kGB7YwX9RxZcO5JkNQZx+FJn5hhEYoiGVpJl8lPM25dwxaNstYAWgskGojM8fCudz5qXuD7geTf1IqS5NNERnyAaJFKngIGk0UfXw9i0lCm+Q+eKdgQVuhicW9c67Lg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769075764; c=relaxed/simple; bh=N8lJFPOlxJuGnNzcSZHaqB6OKRGn99rucfnx664Zc1g=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tfLr9rRrJfBPmVNdVXku2nbvYasOxIIOC0pvfFGlCGzHR3IbGRVC9Pfx33MBBCT+s/YXFF328LYuVJXzU3nMAbRgKLuZ8c/cp3D+4DZqi2A6qzW+Bu6m9V1j6y2hjKyQdBMuEZnGjzrjrs8LBmHbGVt+/yTTV6rZZEGb/H7Z9z4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=C1pujeWd; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C1pujeWd" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-4358fb60802so427623f8f.1 for ; Thu, 22 Jan 2026 01:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769075759; x=1769680559; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=yujnH9wU+TNdDReDnr98/rum5BScCCRa/k+ogGj8Y8E=; b=C1pujeWdiS5+a4Jnl8J2LCd6JU0XyfPEU16eWpNw0+gW/B1rrDzSLXrYh5AehAmWHs 4tOp6K8qsj79AOhtBxZRbDtHz0+70BIEZJF4Xg0dxaD8fr877SAAq3j8KUa+aUlbdHKZ fvBUOqfQZ+8CelrLa+71UtrM0FOWqN3U9O+wSfbmjTi8GzRSxZehH37Xjakd857MeU/4 aeOiLLD4M0Dl1GJyj9a23I4jP6OUrJOjEa87xHeIWXeoYbs/mX4H0bDNG/dVWXxGzKSX egFYIdtgkSS4KqWQAps4Qh2/Eldzuqm/Lph7TP3SfdsgwqVsjNHoTaBJrp/Ye7gB3U5k oAfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769075759; x=1769680559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yujnH9wU+TNdDReDnr98/rum5BScCCRa/k+ogGj8Y8E=; b=Qtrqg3tYeYY5fCsKb9amN3f+iKDrmBjM5BDYeP6+Z8xp2gkkv3FMKDhHxk88D5gv9B K3TbDpujfdO6BZruUSGevYhXCAeb80zf1ErVt9L733NgufKqpOEIypVpD+qDB7WE05od UQdT04/TQRoOGM8yG3hyU8nXsI2djWHKX8eZ6FS2/IVbtb+owh7lFrBUZOWY1t3zGPmP QbygYAkVZBckE4jPiBKpq0ZzLFqSUWlaLZQ8iLhCm9ZL1Vvc+rKRjzagFXwj+BsEyJQH rXSKHUnqzHfBdcEc85N3mvTZG2swTeN8nmzM8A74+31s7fSswMpDIZ7QDeidlPJCKLaB 9Heg== X-Forwarded-Encrypted: i=1; AJvYcCXobreil+5MUqN+pXiG0Tk0y7JF3ZPX5bCXYakWViu1ZS7XZip9+EnsF6hHO5RalGq1rSyZdob+zD0TUV0=@vger.kernel.org X-Gm-Message-State: AOJu0YzJNgNnmXpJuED4eXLSsGljXSJbReGr1BOM36XxRsDQiA2ympIC joI6ehLC9JuBHNp72WZwlokcdcqSz7X2lhiVf1mT57wkJQVDqcNE698NmSDuvA== X-Gm-Gg: AZuq6aLGVysHz7aySNYo6RNLLyMakQ55FkhT9wraBFtXH4EDDMiKA7GQJ+WsQCLT6gQ cFFAL2L8BrM17AkmPj9r9q+PdZrNoVmMPLlIXR1l/I2xd99XzcnEsYK5tN5fp4gIhllG2NCQXc3 jIARQPz7JbJHYjCfIcMBxauxDkq76c7o23OBRVXZfKxdWOxdKqcfAduxV3dgc0kE56XF/7kuQME PcijLUB+P1EAOw6kk3YLVn5UCRE4uTeN9/iPbsOnYzV7V341ujlctyUGR9g0n2JQLjmyatvyZUm n63hax8FwjOOH6hIk1ZaJW8Mlfm+riv/A1juMK3ztjr7otMWkSlhminF3W6XpZ/uEnRbBoHOApk HP2BqWrtr0a4u+X83clyUuTp3KOPXOwlqtJSZewWKmIVlemTzrIU57cR/xTXILLjVjKmCS5Zb4x TJO7jDlByCbjahYpqhXN6TGBuJ4dvHe8G13WvGJqz/RNulmwUoDhC8 X-Received: by 2002:a5d:5d0e:0:b0:430:fdc8:8bd6 with SMTP id ffacd0b85a97d-435a5fa70b4mr4276032f8f.31.1769075758458; Thu, 22 Jan 2026 01:55:58 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4356992201csm44726792f8f.2.2026.01.22.01.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jan 2026 01:55:58 -0800 (PST) Date: Thu, 22 Jan 2026 09:55:56 +0000 From: David Laight To: Arnaldo Carvalho de Melo Cc: Namhyung Kim , Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: Re: [PATCH 3/4] perf list: Don't write to const memory Message-ID: <20260122095556.6e9fe2bd@pumpkin> In-Reply-To: References: <20260120220900.366451-1-acme@kernel.org> <20260120220900.366451-4-acme@kernel.org> <20260121221713.1e7e0cf9@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 21 Jan 2026 22:10:18 -0300 Arnaldo Carvalho de Melo wrote: > On Wed, Jan 21, 2026 at 10:17:13PM +0000, David Laight wrote: > > On Tue, 20 Jan 2026 19:08:59 -0300 > > Arnaldo Carvalho de Melo wrote: > > > > > From: Arnaldo Carvalho de Melo > > > > > > Something now detected on fedora 44, where strchr() returns const if it > > > is passed a const pointer: > > > > > > util/print-events.c: In function 'print_sdt_events': > > > util/print-events.c:89:29: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers] > > > 89 | char *bid = strchr(sdt_name->s, '@'); > > > | ^~~~~~ > > > > > > Fix it by using strnchr() if strchr finds the separator instead of > > > temporarily scrubbing it with '\0'. > > > > I've just looked at the full function to see WTF it is doing. > > You've fixed the second strchr() not the one the compiler bleated about. > > It complained about both, no? > > > Line 89 is followed by: > > if (bid) > > *bid++ = 0; > > but if it is NULL there is a fair chance the code will just explode a bit later on. > > Why, can you elaborate? I don't see why it can't end up in: if (show_detail) { char *path = build_id_cache__origname(bid); with 'bid == NULL' and the function just dereferences it. > > > I suspect it is an error if the strings aren't "name@bar" > > > 'show_detail' seems to be set if either the previous or next entries in the > > list/tree have the same "name" - which seems strange to me. > > All this is strange, a corner case, it looks as if we may have multiple > binaries, differentiated by buildids, that would have different SDTs. > > The code seems to be trying to reduce the amount of info (not showing > the buildid if there are no more at that point multiple versions of a > DSO with SDTs in place). > > Further analysis of the changesets that put all this in place is needed > to clarify, but looking just at fixing what the compiler is complaining, > do you think the patches are bad? I didn't see a patch to fix the first one. But can you just change the structure so that 's' is 'char *'? David > > - Arnaldo > > > The while thing needs more work :-( > > > > David > > > > > > > > Signed-off-by: Arnaldo Carvalho de Melo > > > --- > > > tools/perf/util/print-events.c | 13 +++++-------- > > > 1 file changed, 5 insertions(+), 8 deletions(-) > > > > > > diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c > > > index 8f3ed83853a9e468..898cf426509790cd 100644 > > > --- a/tools/perf/util/print-events.c > > > +++ b/tools/perf/util/print-events.c > > > @@ -97,14 +97,11 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state) > > > } else { > > > next_sdt_name = strlist__next(sdt_name); > > > if (next_sdt_name) { > > > - char *bid2 = strchr(next_sdt_name->s, '@'); > > > - > > > - if (bid2) > > > - *bid2 = '\0'; > > > - if (strcmp(sdt_name->s, next_sdt_name->s) == 0) > > > - show_detail = true; > > > - if (bid2) > > > - *bid2 = '@'; > > > + const char *bid2 = strchr(next_sdt_name->s, '@'); > > > + > > > + show_detail = bid2 ? > > > + strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0 : > > > + strcmp(sdt_name->s, next_sdt_name->s) == 0; > > > } > > > } > > > last_sdt_name = sdt_name->s;