From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CCDCC46467 for ; Mon, 30 May 2022 14:47:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242353AbiE3OqR (ORCPT ); Mon, 30 May 2022 10:46:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240228AbiE3OZK (ORCPT ); Mon, 30 May 2022 10:25:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93469A888B; Mon, 30 May 2022 06:50:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8C74860FE7; Mon, 30 May 2022 13:50:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0955EC3411E; Mon, 30 May 2022 13:50:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653918651; bh=+UxC2I6cB/bAVSQFDihDHHxSOIrE2QoFweh2yYezpEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pPmnQfT1b16DdIkdRK2r2KH7GapxCZyh/sePuFAFK47lOj0TaKsNcuwwE4zxPm0De NG9RaGxIQakdoQtAUvLHdlUIW6qR0RQCMSFO/1P/prLsfjA/wZMcsGX5IPyqOCoPcp 0cQ/NKGF4g3ErsW8xGi+uYCsC4N68oF7lxJUs+tt4HvAa2d4cVBU0qWVbPkOvmrTIN J6vKwlipxpBF6szeFR52vBtR6PhCui+n64r/gXBQD8BlM3Z9g7uX8viUruSmhOHa19 Waahlk+BATtHXUwioujzmmVRIuL528bRVLhI0xXDA77j+G3HuCXP2LcD7j9wgXdl4E wtg+PI9dEC+HQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Guenter Roeck , Sasha Levin , jdelvare@suse.com, corbet@lwn.net, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 36/38] hwmon: Make chip parameter for with_info API mandatory Date: Mon, 30 May 2022 09:49:22 -0400 Message-Id: <20220530134924.1936816-36-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220530134924.1936816-1-sashal@kernel.org> References: <20220530134924.1936816-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guenter Roeck [ Upstream commit ddaefa209c4ac791c1262e97c9b2d0440c8ef1d5 ] Various attempts were made recently to "convert" the old hwmon_device_register() API to devm_hwmon_device_register_with_info() by just changing the function name without actually converting the driver. Prevent this from happening by making the 'chip' parameter of devm_hwmon_device_register_with_info() mandatory. Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- Documentation/hwmon/hwmon-kernel-api.txt | 2 +- drivers/hwmon/hwmon.c | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Documentation/hwmon/hwmon-kernel-api.txt b/Documentation/hwmon/hwmon-kernel-api.txt index eb7a78aebb38..4981df157b04 100644 --- a/Documentation/hwmon/hwmon-kernel-api.txt +++ b/Documentation/hwmon/hwmon-kernel-api.txt @@ -71,7 +71,7 @@ hwmon_device_register_with_info is the most comprehensive and preferred means to register a hardware monitoring device. It creates the standard sysfs attributes in the hardware monitoring core, letting the driver focus on reading from and writing to the chip instead of having to bother with sysfs attributes. -The parent device parameter cannot be NULL with non-NULL chip info. Its +The parent device parameter as well as the chip parameter must not be NULL. Its parameters are described in more detail below. devm_hwmon_device_register_with_info is similar to diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index c4051a3e63c2..fb82d8ee0dd6 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -695,11 +695,12 @@ EXPORT_SYMBOL_GPL(hwmon_device_register_with_groups); /** * hwmon_device_register_with_info - register w/ hwmon - * @dev: the parent device - * @name: hwmon name attribute - * @drvdata: driver data to attach to created device - * @chip: pointer to hwmon chip information + * @dev: the parent device (mandatory) + * @name: hwmon name attribute (mandatory) + * @drvdata: driver data to attach to created device (optional) + * @chip: pointer to hwmon chip information (mandatory) * @extra_groups: pointer to list of additional non-standard attribute groups + * (optional) * * hwmon_device_unregister() must be called when the device is no * longer needed. @@ -712,13 +713,10 @@ hwmon_device_register_with_info(struct device *dev, const char *name, const struct hwmon_chip_info *chip, const struct attribute_group **extra_groups) { - if (!name) - return ERR_PTR(-EINVAL); - - if (chip && (!chip->ops || !chip->ops->is_visible || !chip->info)) + if (!dev || !name || !chip) return ERR_PTR(-EINVAL); - if (chip && !dev) + if (!chip->ops || !chip->ops->is_visible || !chip->info) return ERR_PTR(-EINVAL); return __hwmon_device_register(dev, name, drvdata, chip, extra_groups); -- 2.35.1