From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 202931A2387 for ; Wed, 18 Dec 2024 11:35:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734521719; cv=none; b=F4tBg7iMKKb1XF3r6xUZpeTHpkEFyoW9S1zFXGRoyO6cb2rcQFHlvYxEcXbZ2F7+UDqiX/Eh+zuMmJFIFAY/mcd+uWziSDWzrwB8McegeqVuIL1ydWx5uBIbUsJUinQEY1x++vqoElwYmzk5zH7AvMIWxp1hSwbtNmZu6DpXRx8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734521719; c=relaxed/simple; bh=gOiMAnrjvHN0iPlKNzqS7+6gHJppdNewW/4kpkijjMk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=O0JWR9KYc5hgONEImhTYbzYAGvmYGE0mYple+esz77v3QO8sTa0RwKrMJFD1LKTvJrawqJLd01RXf6mf36dYp/uVZ8MjhlPwF6cVAvtuqo6R2ayHge9L4PSBVi3vRneQUqKkuZfm6o9a9r+kFvM6t6DMMctZHuPj2GXry0S01ps= 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=ZpUpJ5/Q; arc=none smtp.client-ip=209.85.128.45 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="ZpUpJ5/Q" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-436341f575fso50808475e9.1 for ; Wed, 18 Dec 2024 03:35:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1734521715; x=1735126515; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=VlJJETf0GEG5l1fQK2RThJLw2n20sbAz6B1Azi0svlk=; b=ZpUpJ5/QylowrV3JqsfgMS2hgTThrGYcD+Ro6FuLOjXOnzSb+Ex6xpm2JBBXd5PBFd sdkg7ZVOstjiPvW7Lcf+nPLEEHdlVSVZNDpNsE72PusZtbzXFD8xTRO1IkOq+JTclBr3 yJAkS1SGmLqMcdZm7XjTc8kKTXgbdUg2MT2zIk0g90b+ls1WYc/cglquKsPb3fB2/gY0 Owb0e8+cJJ9C55kFffGEWX+BjNuqp7qJVf9rn4A+lQR81nwz9gapEwIOP8F8AbAvRzZ7 9ru4PyeJytdrXNDJhtycxOI8O/CtTqr7x9qNTNCkcrhrCXlcgcvUM2o9ytqmHgn3sjb1 Wiyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734521715; x=1735126515; h=in-reply-to: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=VlJJETf0GEG5l1fQK2RThJLw2n20sbAz6B1Azi0svlk=; b=H4p2CVM/h9D9g29HNeLJXrczqvPm/GJXNjWlglISg/FW+H0ydcS+A2vuwMHdAr+Yx/ 6F/Kt2OY9UEPFcQjfPGziM/TUILD9XLJX3xpnES3jLfNbbibPGT/aKKjEucM4yBQfWhq PLowtM7xqVA7c/Rid7vcwiuIGyCHyZPfYEwXsuH3ICQL14wkHhKtvM9apudPYLN5qDOD ILewG/nD89+0xXG+7WRqfGjd/15crDrfMUOZczeAa/0t6DtH/28Gg3K9lwssc1HhKeTs pbffhpN4rOk/5giCSA74QURFeOrxF5LSqnmMVIIVbmDXXeAcZWgNi0UOTGklIcUVgaUr oiBw== X-Forwarded-Encrypted: i=1; AJvYcCXi7K647ZI3P5JHXZuLRoXNAFnsTzAGz5ZoZVCnfSUv7jZdzjTo3cpDOZhTDzprP0Cb0HatSVCbzOHPs/8=@vger.kernel.org X-Gm-Message-State: AOJu0YztXPxFFc/9R/Y7KizHBvQb7/eKELLwtrnJxSSD7eQ4CtcyM6vO mqdqANwfushwT9m3FJBO28ierPZuE6QQI8sJfejmu1fZYgz+fdSjnMiHOmn3y8Q= X-Gm-Gg: ASbGnctPsshkZacSGw5flNuxVWLRzO9JNHFMz4WdfpK8IAe9piq+enqqFq6OmPAdt7Q Kuofg5jeVGFWcJq9XTZAbSu9VAw6CCN0chEgRoi4VH4e1wiaL79nII2DeOCC0CHcsyO3kAWqSXJ 6/IMsk/b398B8C97wAgeW0cF7GtGetro90jWrrcVUGqzqP0Qf5Z2GEs/s4O2ML+5op9xtjoYdQG 3i2L8z5yjtdt9RWzuK6q278hIpjVGu3Jb6Vz+JhErhuyCqqV3CNTjKpCA== X-Google-Smtp-Source: AGHT+IGnVN8Zbotu5KkOnXCz05raBpseI5GUh9bTzmh4+dTqb3vp6Jmq20mEcYqJv0Y4S8sbzjycFw== X-Received: by 2002:a05:6000:4a16:b0:385:fa26:f0ac with SMTP id ffacd0b85a97d-388e4d6a9aemr2531218f8f.7.1734521715441; Wed, 18 Dec 2024 03:35:15 -0800 (PST) Received: from pathway.suse.cz ([176.114.240.50]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c801223dsm13978802f8f.3.2024.12.18.03.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 03:35:14 -0800 (PST) Date: Wed, 18 Dec 2024 12:35:12 +0100 From: Petr Mladek To: "Rob Herring (Arm)" 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: 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=us-ascii Content-Disposition: inline In-Reply-To: <20241217183711.2525863-1-robh@kernel.org> 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. "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. > { > const char *compat; > char *c; > struct property *p; > - ssize_t csize; > - ssize_t tsize; > - > - /* > - * Prevent a kernel oops in vsnprintf() -- it only allows passing a > - * NULL ptr when the length is also 0. Also filter out the negative > - * lengths... > - */ > - if ((len > 0 && !str) || len < 0) > - return -EINVAL; There is later called csize = snprintf(str, len, "C%s", compat); and snprintf() uses size_t for the len attribute. It would go wild when we pass a negative len. > + size_t csize; > + size_t tsize; > > /* Name & Type */ > /* %p eats all alphanum characters, so %c must be used here */ Best Regards, Petr