From nobody Wed Nov 27 19:32:22 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 6FB70192D7F for ; Fri, 8 Nov 2024 18:47:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731091678; cv=none; b=VBjgalab/LiEmJFnSiVdrrjuK6jAUDmeARUzFGXMURfdh3SnbK9lT2orcSU75uVVAtIs6lkRx+ILcT6Zfsd//CXieTDKn03pIczdpbwhr58SPLeeOOWFjaX0aKhMtc2EmWPKzTP41E81eMdvw+X8YN725i6v2Oi3+6bODG1cIUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731091678; c=relaxed/simple; bh=dniWuxuylHQooe/+O9kS+u+5yRkbVYD7nCVtuNvJa6Q=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=NSL6VsixMaXd6eRPPKFkWNm+d34Qkc1LZljvTvJEYzIMnVbVkmKFRKafOoN5c5DGSL1DXVGXn1mdgtvugao0GM26egqrVSj+7wlu40S2eMVLWp9tJdtBzJD6rd5j2UMMOnNmsF4QxnbOyJ7PSg9fgSiazPhhsuTFA3xlxCRV2Oc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=i3rzw5I9; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="i3rzw5I9" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e33152c8225so5189928276.0 for ; Fri, 08 Nov 2024 10:47:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731091676; x=1731696476; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=rfQP4ZowKoUcMreOGn+KjRxwFgZW88CzOPZZCNSZnMI=; b=i3rzw5I9cOgZzJf6jVId1Gi8pFfonDCIq1su10GHG0s8xAKzocyZfJMNgGUvAbBJLs 8ONnvl8yPjVLcQ2t8/BzbJ/fWQan+vb3mdmozzqLpqzQEnDVtY8Et9mALAlp0wjvo7V9 1cjtSuHUZD+USaqI9Fv4A30OS4kXdgbyTbGowTWINi9goEhNXI5fwLCB8S6l6oYP11x5 phzty9neXDeZSQano7HWZTjGTzMSsRDZ2UXKNjcgTkSrbqxQakmXmj2X5NQ2arya99m+ WPQqX+YRm7OsQlyDYvAHowT3Q036ytjXY1yF0GHdsKWK2D4cdNdJXv8uaNaEMnWcREX2 yGLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731091676; x=1731696476; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rfQP4ZowKoUcMreOGn+KjRxwFgZW88CzOPZZCNSZnMI=; b=YRNzQvl7xf+6KCFB8f0qvzLjI2MLN6hdDOY7ivtJ6cNZYiP3dRwnieAFrg6PafUmzX lqdlkeFG1U2/bLy8JNoUx461L5feLaFvQ4s2PEL/edQoqDtwNlW3S7igRr6pZtmBfiYS 0On5PDgna718XKqgUY00IW8A+ZdEZKjrd/208xymt6zz/Dd3xwu6UQq3utcLvqcorbQV 3+aJ+VUF3o3uQzmxp92sK5bfoFn0onIlszYQ7YQPtZsseC6pT3M2UL6Fiws5AwRk8Ghp 5G5uuDwb/yS72sw5odr0Tqmol6OVXk6zzCMG49QRQTtW8bYhTXz5Bjy6/qaRKUzaC4Hc V7Hg== X-Forwarded-Encrypted: i=1; AJvYcCU5Kj+0aqNH49XPDhCVS1jh6dLpRs8wgX8HX7Nqf5p96hcErzyQpsRcIcEmOsEwhy5mPqyFodDrfXkVMZU=@vger.kernel.org X-Gm-Message-State: AOJu0Yxbb5I0OFe2D3njamNTNuZQDH6DzsaYUQZ+pqfdkczYYY1kMY/p ZIVLux0NnVd5EFvp/mBA011SfYo3lvpTPcQtnrXNKl9pUXZPSYMuD5GUuuTNR1AAXo7URYX840N //9sSrA== X-Google-Smtp-Source: AGHT+IHSUecJfqyP6yo6pYHHwXlmFb3TtyJAgM28FJPeh82MRvOLqxptoEEBE92c8/yyBMaC2YcowXN+ItIJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:6fd2:1e36:6d8c:7c49]) (user=irogers job=sendgmr) by 2002:a25:dc4a:0:b0:e25:5cb1:77d8 with SMTP id 3f1490d57ef6-e337f8ed8bbmr2368276.6.1731091676429; Fri, 08 Nov 2024 10:47:56 -0800 (PST) Date: Fri, 8 Nov 2024 10:47:46 -0800 In-Reply-To: <20241108184751.359237-1-irogers@google.com> Message-Id: <20241108184751.359237-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241108184751.359237-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v4 1/6] tool api fs: Correctly encode errno for read/write open failures From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Athira Jajeev , James Clark , Dominique Martinet , Yang Li , Colin Ian King , Yang Jihong , "Steinar H. Gunderson" , Oliver Upton , Ilkka Koskinen , Ze Gao , Weilin Wang , Ben Gainey , zhaimingbing , Zixian Cai , Andi Kleen , Paran Lee , Thomas Falcon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, "Steven Rostedt (Google)" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch from returning -1 to -errno so that callers can determine types of failure. Signed-off-by: Ian Rogers --- tools/lib/api/fs/fs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c index 337fde770e45..edec23406dbc 100644 --- a/tools/lib/api/fs/fs.c +++ b/tools/lib/api/fs/fs.c @@ -296,7 +296,7 @@ int filename__read_int(const char *filename, int *value) int fd =3D open(filename, O_RDONLY), err =3D -1; =20 if (fd < 0) - return -1; + return -errno; =20 if (read(fd, line, sizeof(line)) > 0) { *value =3D atoi(line); @@ -314,7 +314,7 @@ static int filename__read_ull_base(const char *filename, int fd =3D open(filename, O_RDONLY), err =3D -1; =20 if (fd < 0) - return -1; + return -errno; =20 if (read(fd, line, sizeof(line)) > 0) { *value =3D strtoull(line, NULL, base); @@ -372,7 +372,7 @@ int filename__write_int(const char *filename, int value) char buf[64]; =20 if (fd < 0) - return err; + return -errno; =20 sprintf(buf, "%d", value); if (write(fd, buf, sizeof(buf)) =3D=3D sizeof(buf)) --=20 2.47.0.277.g8800431eea-goog