| Message ID | 20260403140523.1998228-6-sjg@u-boot.org |
|---|---|
| State | New |
| Headers |
Return-Path: <concept-bounces+u-boot-concept=u-boot.org@u-boot.org> X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775225163; bh=EhcH9Y2Q1Vj2/22keGrc6V4PwlcoGo6D+YTEVVPZtzg=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=pxaKW4/hHGKJGNA3tKKO2ti5W1/4GrA+arUn8IikeCbaR6i1Iw5I1Gl/ezRRXKwgE Dvq8wz7U9+1NxT267wxnUnI8CptNy3a9/PVrlyJlzfuoEVFMB6MslSl5A5Xq3+hEmH 0uUsLVgPIIBjQsDzDQXw4prsGO6Z/t03EkyweiSJBnZeR32Z1R06w9Sz1OIEE0iWy1 CXiomFAt5xoegIKTdcNcDOuUWWelP80u4IADlWCJoBHXURUFs6RkP2bYcz+MsGKnZV zQlWDX1jHcTzHywDhHwQIWRK37wB5o3ISYDrACVR8cIM2w1ZbzQkoIMb6UgkEw8moY 0tS9HeB4ejtJw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7B82B6A363 for <u-boot-concept@u-boot.org>; Fri, 3 Apr 2026 08:06:03 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id k5jVCdfDuuQj for <u-boot-concept@u-boot.org>; Fri, 3 Apr 2026 08:06:03 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775225159; bh=EhcH9Y2Q1Vj2/22keGrc6V4PwlcoGo6D+YTEVVPZtzg=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=SyvmrL3F0KPIxcRnWw1ELGJeqw8B5wpB7fqWRT2uB8BieCMDFjXiFANWqyQiiReSP ZAUzNQwlvnHAhzC7GaKuuFoVEigcqrJKxNcIX/2rlZmIYV5m5kmJgYgcoJO+vz17F6 fvJtsqdySRplZwMZJl6beoVZgtExrI9zxcqDs7BiaZWj+G+ygwo28lHLwRVRsAb90V +kdwyZoCKNvTIXzJ0nHAKvHHwOiHOX2m88woXX3VgvLh/uAHYFwgtGR6uY77QM44Kp LaZV+yBFsLdZ4sdIQtjldrVP24WIsb2OIxMIgeDyVfHBEo2BJtQLmTxUkPtsJsX4lI d+QEm9Dxy/B1Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4A0406A367 for <u-boot-concept@u-boot.org>; Fri, 3 Apr 2026 08:05:59 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775225155; bh=i1QKN68+cNBpjlntljcoxqKr+iDLcLYyfQRCu0imYvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TLONNbikpcwr7XdZ21Bk7tfo/X8zkIjUmDBWvOrN74xg790vv8n8AeT3xxwOAFBed UbqwIV9FTxAlycnz8fiFnhFCrUrzfgL1HL0QgoVrSZLtx7qjIliSY92Qb91FNEWTzJ H2JzqYLmQ0iMp4Xw8TT6+op5tJ/vnrh0/BV47yZgbdpONPhpq0OMsORHt9wYOE2jNs Qpt9mVaO20kkMGOjcBZnDjTqmjtflZGWaGzLyiatLGVgyA6VT4uPFRFYb3jwPYQ/Bg 9w2FyaH9QcYxq0yHhCHAGiOgNvIW4EvsnAdV/NG5RHVbnbnasva82QJrsh6wHpvanQ fRi7eRQ8kyLjA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7FCD767EE6; Fri, 3 Apr 2026 08:05:55 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id rHrytRHn5cjS; Fri, 3 Apr 2026 08:05:55 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775225154; bh=WA0ZdeOTxMsK0vDFG42UyE+Fzbp630RYqlOh9ay5JqY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VKWNam8Pd1GBu/RHErUibEAdmMFpG9QRT1StLQDS3A7gaIJFcuHQZ6Hafkt066ZxC QvYEI3946TbcI3HFkyNbfXateJF4PGywS/RQc2pbruB6S7c8RxWYqK45ntllrnzjs8 eQe1nLeIGibfFPLzkQe59PLqAj1323A5OGmfghpBbDaXaYFktqJyxYH08lYdNVbC77 ioJSteOOga6DGIdHe+DjsEpLSUTQPNpadStS4ruB4wEQq90OaXz89Gyp9zvVbaU4Lr AaGfu1aXZ1kTBxKl9lDKsuQ+xu6QnW+iuhT2xEVATs72BeGdCpkhNwJmneEel8eZLP Pj4xF7hsnU9aA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id E20C26A34C; Fri, 3 Apr 2026 08:05:53 -0600 (MDT) From: Simon Glass <sjg@u-boot.org> To: U-Boot Concept <concept@u-boot.org> Date: Fri, 3 Apr 2026 08:04:27 -0600 Message-ID: <20260403140523.1998228-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260403140523.1998228-1-sjg@u-boot.org> References: <20260403140523.1998228-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: JQDUEIO2CVJWEARCIAVW2FTTRTLPVEL7 X-Message-ID-Hash: JQDUEIO2CVJWEARCIAVW2FTTRTLPVEL7 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass <sjg@chromium.org> X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/34] vfs: Tidy fs_split_path() allocation List-Id: Discussion and patches related to U-Boot Concept <concept.u-boot.org> Archived-At: <https://lists.u-boot.org/archives/list/concept@u-boot.org/message/JQDUEIO2CVJWEARCIAVW2FTTRTLPVEL7/> List-Archive: <https://lists.u-boot.org/archives/list/concept@u-boot.org/> List-Help: <mailto:concept-request@u-boot.org?subject=help> List-Owner: <mailto:concept-owner@u-boot.org> List-Post: <mailto:concept@u-boot.org> List-Subscribe: <mailto:concept-join@u-boot.org> List-Unsubscribe: <mailto:concept-leave@u-boot.org> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit |
| Series |
Add a virtual filesystem (VFS) layer to U-Boot
|
|
Commit Message
Simon Glass
April 3, 2026, 2:04 p.m. UTC
From: Simon Glass <sjg@chromium.org> fs_split_path() duplicates the entire filename then truncates it to get the directory part. Instead, find the last slash first and only allocate the directory portion. When there is no slash at all, return an empty string rather than "/" since a bare filename has no directory component. Signed-off-by: Simon Glass <sjg@chromium.org> --- fs/fs-uclass.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/fs/fs-uclass.c b/fs/fs-uclass.c index a335391bd74..6bb50bb2543 100644 --- a/fs/fs-uclass.c +++ b/fs/fs-uclass.c @@ -12,27 +12,34 @@ #include <dir.h> #include <dm.h> #include <fs.h> +#include <malloc.h> #include <dm/device-internal.h> int fs_split_path(const char *fname, char **subdirp, const char **leafp) { - char *subdir, *p; + const char *last_slash; + char *subdir; if (!*fname) return log_msg_ret("fsp", -EINVAL); - /* allocate space for the whole filename, for simplicity */ - subdir = strdup(fname); - if (!subdir) - return log_msg_ret("fsp", -ENOMEM); - - p = strrchr(subdir, '/'); - if (p) { - *leafp = p + 1; - *p = '\0'; + last_slash = strrchr(fname, '/'); + if (last_slash) { + int dir_len = last_slash - fname; + + if (!dir_len) + dir_len = 1; /* root "/" */ + subdir = malloc(dir_len + 1); + if (!subdir) + return log_msg_ret("fsp", -ENOMEM); + memcpy(subdir, fname, dir_len); + subdir[dir_len] = '\0'; + *leafp = last_slash + 1; } else { + subdir = strdup(""); + if (!subdir) + return log_msg_ret("fsp", -ENOMEM); *leafp = fname; - strcpy(subdir, "/"); } *subdirp = subdir;