From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 4B1F422540B for ; Thu, 19 Dec 2024 14:44:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734619465; cv=none; b=ovDgIndknOxXbq+3NJb3+lddV3ghZfNmntPmlPbYmB6lBjTHzRj+rDQLx9VAr0a5G10Iv5kHPUZuorm580XHqAesAYFYajYOLy/sFPKn4vqP/m91B2Zz5G5whAxJhRonzvYuA62qFbjV75SZPvEu8kwJP9cY2DzWhfyELzdH5jg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734619465; c=relaxed/simple; bh=kuzNS9K72EkSrNeLIVLdw6jZ00C6nGxLQgNNkN4fUXI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TpPSfD6vHrJW4UrVUJI6nZCQ1fUzfZ44ge4DGcz4HiGHs6vX/TMUPoURLzNyUqJEi/LkcrUEIcptWYFfUOpVlVkvzhj3o4HmyAiiTCeVrpdK5rZlNlvtpFzEqjH/oM0+HmJFKS6HpPZI/ytwH45I/PoHJTWDqJfXmpIg8e72e0M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=YDlLqmwq; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="YDlLqmwq" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-385deda28b3so618045f8f.0 for ; Thu, 19 Dec 2024 06:44:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1734619461; x=1735224261; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=YUe8L/RSJG7X1qPU8YCoCZFztQIhaGAvtLCydCuhUAE=; b=YDlLqmwqvuSeLVYSYfeKdn3Zfsvrc53LUH36k23y2JdV14mWysgKFmbZezRaZwhljR +y7rpaWlpOWhnig/LkDhgDxbUroY1tAWngBBUy8Dnxyej3nE/h3gJfENRsrDuuUZPx7C 7ew6MNPRHPZDm+OGDt88FNGW/DbsqSVuAB6iTkVD8+j5Geh2FX901kGxL2d9nDUWDqAl VSRq+o6XjsOqBVbVUU4G3TdgYm9wy7F1nQ0NYXnzWUW39FsmnB/ATIozCk/dKCxyYj/2 6Rv+zonOlHt856ZGyP0pZNX1Q9LzxkwP5f3Lomy3CuzX7b9HP99FmY2HjV4+m3okH7da t+uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619461; x=1735224261; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YUe8L/RSJG7X1qPU8YCoCZFztQIhaGAvtLCydCuhUAE=; b=CTlf5QFiYcblF7Q22fV/j1cXY/5RuVAr4fw0gtOneiCljbFImW02FUkBud7ehH2LWD wrtOAlzbvAcTZ+AT/5tdRW6iIh59xzDLwyZgIVlAiAeL4d2ungTByJ4hT/cZqzdApYYt DtAXXFlMmyMKkp3CmXka2yCcLulYxIMjfQrdmKSArvI8YvNAcerDpsuCHV2TevqGpX1j GrZRGtciUExrEect72ne30eIDslNt0NQ6rUL4rePC2qoQ8eJzeooUsyzCgalqbaXF014 7R5+FNA4nILGIf6XhLIalIiP02/esFUnEm6UgBOqi7MDJgwilGOvZSVeuaUNpDMNPwIs b8Vw== X-Forwarded-Encrypted: i=1; AJvYcCUkm3Bly3EVk+Wk0MZIGj85VYdSqdVg9Q4EEzGYRC2At+kNXT/T8IcQSBELwbRw8EklGwIX8zDniwrynPc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz29jvbvFarB09IiKY0n9uYfzoXR3N9fB5P23sZMlYAC90Ci+nA 60/AP4RAS02TPJtT5faWNFAfRn7Pct6XbRehsI+UbdAjqJ50CFKX57xNDCe05Zb9YFRBzTMrZ06 d X-Gm-Gg: ASbGncuXJUVG4b6KJaPTFgZIlwjDoxOU4TQcooLNNdaKbvFEDr4g2xExIxM39GaFHX6 Hh+brEDWJV2y1yfeEp6w0JnkAOVsBn41MsGJIqV5hj+pjWsvv+7WXOIW24oju8+miaf1fcTzZfF +NovczxjK9ET+YJA6GbpQdi+YroJmfg4rrZfVQTEO1tn0U4ZOFQF2gF5dSNSq5Bih6E1BYeDo9j wDjDMsUuPNd27hHhfZy42QVM0t6yuU26BceV7LV6IXDM2W3nxbu8DYLZg== X-Google-Smtp-Source: AGHT+IETUPBPDpfMGSiHPHr2l+GQu1KRtFJb1OUCyY4yEHQND0y6u+pyC88kJZkjcOETPOdloGbAvQ== X-Received: by 2002:a05:6000:1867:b0:385:fd07:85f4 with SMTP id ffacd0b85a97d-388e4d64711mr7110212f8f.31.1734619461577; Thu, 19 Dec 2024 06:44:21 -0800 (PST) Received: from pathway.suse.cz ([176.114.240.50]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c8add5asm1677939f8f.107.2024.12.19.06.44.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 06:44:21 -0800 (PST) Date: Thu, 19 Dec 2024 15:44:18 +0100 From: Petr Mladek To: Rob Herring Cc: Steven Rostedt , Andy Shevchenko , Rasmus Villemoes , Sergey Senozhatsky , Jonathan Corbet , Saravana Kannan , Andrew Morton , Zijun Hu , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: ssize_t: was: Re: [PATCH] of: Add printf '%pOFm' for generating modalias Message-ID: References: <20241217183711.2525863-1-robh@kernel.org> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed 2024-12-18 11:10:54, Rob Herring wrote: > On Wed, Dec 18, 2024 at 5:35 AM Petr Mladek wrote: > > > > On Tue 2024-12-17 12:37:09, Rob Herring (Arm) wrote: > > > The callers for of_modalias() generally need the module alias as part of > > > some larger string. That results in some error prone manipulation of the > > > buffer prepend/append the module alias string. In fact, > > > of_device_uevent_modalias() has several issues. First, it's off by one > > > too few characters in utilization of the full buffer. Second, the error > > > paths leave OF_MODALIAS with a truncated value when in the end nothing > > > should be added to the buffer. It is also fragile because it needs > > > internal details of struct kobj_uevent_env. add_uevent_var() really > > > wants to write the env variable and value in one shot which would need > > > either a temporary buffer for value or a format specifier. > > > > > > Fix these issues by adding a new printf format specifier, "%pOFm". With > > > the format specifier in place, simplify all the callers of > > > of_modalias(). of_modalias() can also be simplified with vsprintf() > > > being the only caller as it avoids the error conditions. > > > > > > --- a/drivers/of/module.c > > > +++ b/drivers/of/module.c > > > @@ -8,21 +8,14 @@ > > > #include > > > #include > > > > > > -ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len) > > > +/* Do not use directly, use %pOFm format specifier instead */ > > > +size_t of_modalias(const struct device_node *np, char *str, size_t len) > > > > We should keep ssize_t. > > My intent was to align of_modalias() with snprintf()... Sure. > > "end - buf" passed from device_node_string() in vprintf.c might be > > negative. The "buf" pointer is used to count the number of characters > > which might be written when the buffer is big enough. > > Isn't Rasmus' suggestion sufficient?: > > buf += of_modalias(dn, buf, buf < end ? end - buf : 0) Yes, this should do the trick. I sent my overview before reading Rasmus' reply. Best Regards, Petr