From patchwork Mon Apr 7 15:44:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 878936 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69AF520550E; Mon, 7 Apr 2025 15:49:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744040986; cv=none; b=tDtIpnblK1upezcx5AK/1s8CE37RRh+44D5umEnExQllbHt5FFhTCLKfcvZzM9UkCYyqE7fVcIJbK/F+1uiIHmRMpGj+23gtdMRvw7cFXzssnmSypujmf+OCyi25BA7nXpARYDfOjRK59OA/9Xv8QkFJ/yBAo1WjsAKIAA/qccs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744040986; c=relaxed/simple; bh=WNQV/Tzpdu538d4f1vf/iAGrn+2oUnFD71DxzinbQkg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r0Cq8MR0cREq6LrAYus7EHtqb2o62un8UySBFud2P+GJmak+vHaWKwFpQUe+gIn2MzIsDmFnKet9mDmyy9cwnJFTUX49hsXAxMH9StybSr1Blom5xIJb0oa0vPjL6g3oPxYiomvGVV4LC4vEWzRh7WhUH1j/mahPcvqBpysrdzo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=b6pjfh23; arc=none smtp.client-ip=192.198.163.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="b6pjfh23" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744040983; x=1775576983; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WNQV/Tzpdu538d4f1vf/iAGrn+2oUnFD71DxzinbQkg=; b=b6pjfh23Z7+rjk1/tJAtMj6AauPwOTl8KSfFDL2l0ODIdo28uIMaYOaV XqDOWqmVBySOS5umwMJCyoRvqcYnYJaB0gVd+UhLW+Q/2JW/REN7KDRk/ 04cyKncPch9rR9PoKhp7DjPeCwMUASD8HwrpUBX+0YyNuSVl1GeDeJuYz Uogi+8zFA0Ir3FUZHN4f+m5FVrna8XAR1mTjeqLMFyvqnsz7qXx00sAI+ sh8nrZh4TFPqCbCQjw4JFd7x4p3XaLOtWjGzJDfjksxbQi51Q/FX6vFAH v/sN5lX6tzcPHt/hDRLCA8Ja7Eq+n6RNnlC48MtlwFvMEbyquDFCergPd Q==; X-CSE-ConnectionGUID: 8uIcuy/PT06hSv2oAOehrg== X-CSE-MsgGUID: mUg2DlQ8RQmGmwC1mFW7Bw== X-IronPort-AV: E=McAfee;i="6700,10204,11397"; a="45555055" X-IronPort-AV: E=Sophos;i="6.15,194,1739865600"; d="scan'208";a="45555055" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2025 08:49:42 -0700 X-CSE-ConnectionGUID: bJkBTVvJTHKyNLoqZVMUKQ== X-CSE-MsgGUID: YndHSyqrTIm3B9IEhUrqbA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,194,1739865600"; d="scan'208";a="158986650" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa002.jf.intel.com with ESMTP; 07 Apr 2025 08:49:40 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 9E8AD157; Mon, 07 Apr 2025 18:49:38 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Sakari Ailus , Mauro Carvalho Chehab , Tomi Valkeinen , Jai Luthra , Wolfram Sang , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Cc: Mauro Carvalho Chehab Subject: [PATCH v3 2/7] i2c: core: Unify the firmware node type check Date: Mon, 7 Apr 2025 18:44:58 +0300 Message-ID: <20250407154937.744466-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250407154937.744466-1-andriy.shevchenko@linux.intel.com> References: <20250407154937.744466-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 OF and ACPI currently are using asymmetrical APIs to check for the firmware node type. Unify them by using is_*_node() against struct fwnode_handle pointer. Tested-by: Tomi Valkeinen Signed-off-by: Andy Shevchenko --- drivers/i2c/i2c-core-base.c | 14 ++++++++------ drivers/i2c/i2c-core-slave.c | 12 ++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 0d850d425734..b320a20957ed 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -494,6 +494,7 @@ static int i2c_smbus_host_notify_to_irq(const struct i2c_client *client) static int i2c_device_probe(struct device *dev) { + struct fwnode_handle *fwnode = dev_fwnode(dev); struct i2c_client *client = i2c_verify_client(dev); struct i2c_driver *driver; bool do_power_on; @@ -512,11 +513,11 @@ static int i2c_device_probe(struct device *dev) /* Keep adapter active when Host Notify is required */ pm_runtime_get_sync(&client->adapter->dev); irq = i2c_smbus_host_notify_to_irq(client); - } else if (dev->of_node) { + } else if (is_of_node(fwnode)) { irq = of_irq_get_byname(dev->of_node, "irq"); if (irq == -EINVAL || irq == -ENODATA) irq = of_irq_get(dev->of_node, 0); - } else if (ACPI_COMPANION(dev)) { + } else if (is_acpi_device_node(fwnode)) { bool wake_capable; irq = i2c_acpi_get_irq(client, &wake_capable); @@ -1058,15 +1059,16 @@ EXPORT_SYMBOL_GPL(i2c_new_client_device); */ void i2c_unregister_device(struct i2c_client *client) { + struct fwnode_handle *fwnode; + if (IS_ERR_OR_NULL(client)) return; - if (client->dev.of_node) { + fwnode = dev_fwnode(&client->dev); + if (is_of_node(fwnode)) { of_node_clear_flag(client->dev.of_node, OF_POPULATED); of_node_put(client->dev.of_node); - } - - if (ACPI_COMPANION(&client->dev)) + } else if (is_acpi_device_node(fwnode)) acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev)); device_remove_software_node(&client->dev); diff --git a/drivers/i2c/i2c-core-slave.c b/drivers/i2c/i2c-core-slave.c index faefe1dfa8e5..7ee6b992b835 100644 --- a/drivers/i2c/i2c-core-slave.c +++ b/drivers/i2c/i2c-core-slave.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "i2c-core.h" @@ -108,15 +109,18 @@ EXPORT_SYMBOL_GPL(i2c_slave_event); */ bool i2c_detect_slave_mode(struct device *dev) { - if (IS_BUILTIN(CONFIG_OF) && dev->of_node) { + struct fwnode_handle *fwnode = dev_fwnode(dev); + + if (is_of_node(fwnode)) { + struct fwnode_handle *child __free(fwnode_handle) = NULL; u32 reg; - for_each_child_of_node_scoped(dev->of_node, child) { - of_property_read_u32(child, "reg", ®); + fwnode_for_each_child_node(fwnode, child) { + fwnode_property_read_u32(child, "reg", ®); if (reg & I2C_OWN_SLAVE_ADDRESS) return true; } - } else if (IS_BUILTIN(CONFIG_ACPI) && ACPI_HANDLE(dev)) { + } else if (is_acpi_device_node(fwnode)) { dev_dbg(dev, "ACPI slave is not supported yet\n"); } return false; From patchwork Mon Apr 7 15:44:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 878935 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 029D720551E; Mon, 7 Apr 2025 15:49:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744040987; cv=none; b=aemGZYa+gPDWY03Y85i9GrxY8Tx7JM21azqhEliBnzJYrPU1gbrDZ3MpBUpVWlQLrcCt+eiK0Hk7rtiLBnel72bak61af/cVq/OVbV4DwsCYatfpwmaj45m3LQd79vEGjDA6zeZVto5jJXp43b0RSjfF5GeKAElecqLAfLvgqyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744040987; c=relaxed/simple; bh=A8BGhNibWN5ifckpQkEKkfZ63fbS3e4jO+HGW/FXJVs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C6R7Jz3ZhgkSgzVwnE0sTFCiakTs1TRG0dhK+9eiJCUzw8cwouXLLLJ7PeKqRTIr7fchPtjF9c8a5J3kHtC+RADFrSVtthUUwmlCj3aOOU4PRf/KNTukPs/qWkuBQ65j8ZGAk4+FoIsI6IN99nbJ9bI6WWwrLavV3ursN7d5Uow= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Nc5De0uq; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Nc5De0uq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744040986; x=1775576986; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=A8BGhNibWN5ifckpQkEKkfZ63fbS3e4jO+HGW/FXJVs=; b=Nc5De0uqIL2JjcrTzhWWSQF8FFbH8PZuYIq4LuRIwtk1+zUeNzD0jegJ ZRKmGRdaCAdd8LMdlpDhqCmEYcuEzbzXR5HtO9V2QYW83e/UDRaQYtvPi 4lEdmF/B2JI1zonjSpMu3QAjmPLlSxtOsqOlZAV4hL8AVbYAr+t7S0FGd QE2MQBgynQoS2oHXVRaz+g0S3Tmai8KPNiQoLidXDS6sM05b3+HZDWuP3 5yZj7dio6Obv45u6joBmePy6t+Qodz/avv6qchJFXiO68rqRkeNM0tovw jzdACI80r/mIJB/kP3OUu0GFg0WjuhodKh5RNRPXvzimIdEzMdKrwUBrR A==; X-CSE-ConnectionGUID: 6Htm6L9zQA2Du6N6cixJqw== X-CSE-MsgGUID: HNH+NOGGQUCnzpnqSYoPLw== X-IronPort-AV: E=McAfee;i="6700,10204,11397"; a="45324198" X-IronPort-AV: E=Sophos;i="6.15,194,1739865600"; d="scan'208";a="45324198" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2025 08:49:43 -0700 X-CSE-ConnectionGUID: w3D+r0adQhqt80khcOt7WA== X-CSE-MsgGUID: NLDambi6TROoIH7uHCYhbQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,194,1739865600"; d="scan'208";a="128930034" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa008.jf.intel.com with ESMTP; 07 Apr 2025 08:49:40 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id AAA45245; Mon, 07 Apr 2025 18:49:38 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Sakari Ailus , Mauro Carvalho Chehab , Tomi Valkeinen , Jai Luthra , Wolfram Sang , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Cc: Mauro Carvalho Chehab Subject: [PATCH v3 3/7] i2c: core: Switch to fwnode APIs to get IRQ Date: Mon, 7 Apr 2025 18:44:59 +0300 Message-ID: <20250407154937.744466-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250407154937.744466-1-andriy.shevchenko@linux.intel.com> References: <20250407154937.744466-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Switch to fwnode APIs to get IRQ. In particular this enables a support of the separate wakeup IRQ. The rest is converted just for the sake of consistency and fwnode reuse. Tested-by: Tomi Valkeinen Signed-off-by: Andy Shevchenko --- drivers/i2c/i2c-core-base.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index b320a20957ed..e2fdfbdb1bd7 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -26,14 +26,13 @@ #include #include #include -#include +#include #include #include #include #include #include #include -#include #include #include #include @@ -514,9 +513,9 @@ static int i2c_device_probe(struct device *dev) pm_runtime_get_sync(&client->adapter->dev); irq = i2c_smbus_host_notify_to_irq(client); } else if (is_of_node(fwnode)) { - irq = of_irq_get_byname(dev->of_node, "irq"); + irq = fwnode_irq_get_byname(fwnode, "irq"); if (irq == -EINVAL || irq == -ENODATA) - irq = of_irq_get(dev->of_node, 0); + irq = fwnode_irq_get(fwnode, 0); } else if (is_acpi_device_node(fwnode)) { bool wake_capable; @@ -551,7 +550,7 @@ static int i2c_device_probe(struct device *dev) if (client->flags & I2C_CLIENT_WAKE) { int wakeirq; - wakeirq = of_irq_get_byname(dev->of_node, "wakeup"); + wakeirq = fwnode_irq_get_byname(fwnode, "wakeup"); if (wakeirq == -EPROBE_DEFER) { status = wakeirq; goto put_sync_adapter; From patchwork Mon Apr 7 15:45:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 878933 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 206AD205E36; Mon, 7 Apr 2025 15:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744040988; cv=none; b=jCgaT9vwCUbm5Qsoq4jGKx61pwr+L1Ldai30Lf0uIbwc3Uav+2MoENwrFBCrcZ5BOnstJSCdEIczV3yrn/1QYCPxLKUcOAnJ+OTd1/lJPdM3cX0YhpJOARaKgA1FneS4QAJfq6qWlIOHVnuky3Pc4FEfdG1iNau19U7Atzy0kck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744040988; c=relaxed/simple; bh=13O5W3bCuiHDF3L9eBsuHmrbVsCq2QcoZklOEK2ib0Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rdXU2qToU2+7r9BVSKQGd5qm6YZqBkmsH44JWyh+sZ1JdtA7iJdQQ8KX8Y1X80TH4zcHM4oHEqUy4ajlD/a7vA2c1QCUEVfM96/dqnoDA5k0PrC9FH9eTwkecaFyqTU3hCgdh+32TyQUTdhqvjFNa6zTyez2suBdfG88Eoilve0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=euEzV6oW; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="euEzV6oW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744040987; x=1775576987; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=13O5W3bCuiHDF3L9eBsuHmrbVsCq2QcoZklOEK2ib0Y=; b=euEzV6oWG1obRFuYvuaIngZQafeUekHpe8Mk4fqj7mIoNY5Qn2mY6/o7 Hco72sIwFQdAB6+1orAQhVfF2OmRQmGRCeA1PxN3OXiNwej1795UsbpND NMQcSII4P6uyaTSB8kcghF+PZ+qmqmKwQ+r6u+BJ2C+mKg8nc1iqWE2Z6 Gi4YmlSUtJzo/PWUmJ8WxM8N9LU+1ZdQUQ+Eygn02sIzItAzJth41W+Om 0b3rDgeo7g75XQyUPYhj9006unSy22MPTS9JGQwqLwiC8OJ6gx3yCtwV7 vWsHZkEDQGLdeqsPZNKw3rfaB5kXZGS5IcLVJT1zaeN5TxLvXjVqQVC2i g==; X-CSE-ConnectionGUID: T6sT9/r2RGq6mta7RLgrUA== X-CSE-MsgGUID: 5jYivJjbQEyW2rvaxS7Big== X-IronPort-AV: E=McAfee;i="6700,10204,11397"; a="45324202" X-IronPort-AV: E=Sophos;i="6.15,194,1739865600"; d="scan'208";a="45324202" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2025 08:49:43 -0700 X-CSE-ConnectionGUID: qngkipzXRAaeQC0M+xbcog== X-CSE-MsgGUID: YxflcNHNTU2os4L0/+YyAg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,194,1739865600"; d="scan'208";a="128930033" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa008.jf.intel.com with ESMTP; 07 Apr 2025 08:49:40 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id B2C6D26D; Mon, 07 Apr 2025 18:49:38 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Sakari Ailus , Mauro Carvalho Chehab , Tomi Valkeinen , Jai Luthra , Wolfram Sang , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Cc: Mauro Carvalho Chehab Subject: [PATCH v3 4/7] i2c: core: Reuse fwnode variable where it makes sense Date: Mon, 7 Apr 2025 18:45:00 +0300 Message-ID: <20250407154937.744466-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250407154937.744466-1-andriy.shevchenko@linux.intel.com> References: <20250407154937.744466-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reuse fwnode variable where it makes sense. This avoids unneeded duplication hidden in some macros and unifies the code for different types of fwnode. Tested-by: Tomi Valkeinen Signed-off-by: Andy Shevchenko --- drivers/i2c/i2c-core-base.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index e2fdfbdb1bd7..c92badadd47a 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -571,7 +571,7 @@ static int i2c_device_probe(struct device *dev) dev_dbg(dev, "probe\n"); - status = of_clk_set_defaults(dev->of_node, false); + status = of_clk_set_defaults(to_of_node(fwnode), false); if (status < 0) goto err_clear_wakeup_irq; @@ -1065,10 +1065,10 @@ void i2c_unregister_device(struct i2c_client *client) fwnode = dev_fwnode(&client->dev); if (is_of_node(fwnode)) { - of_node_clear_flag(client->dev.of_node, OF_POPULATED); + of_node_clear_flag(to_of_node(fwnode), OF_POPULATED); of_node_put(client->dev.of_node); } else if (is_acpi_device_node(fwnode)) - acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev)); + acpi_device_clear_enumerated(to_acpi_device_node(fwnode)); device_remove_software_node(&client->dev); device_unregister(&client->dev); From patchwork Mon Apr 7 15:45:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 878934 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60D20205E0D; Mon, 7 Apr 2025 15:49:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744040988; cv=none; b=oounBGaUuKGDNzVAxSi02VTyLmdw587nKIxjKCkyc0M8JlBiRRyEV0Ok8YBwwlZ3I2VAONrRQduo52VQzezG0PgBJnT3yjBSvV/sHxKmMIu509ipnWcSwDVvONDW43J5rMuNkWvZd1mOHF4JHvL64G/aC2KKWI93EvkfaCfj9G8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744040988; c=relaxed/simple; bh=ocKwfB6Vxkwa5A0pOC/2iu6YUSeofDIGwtON0zWaRqc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PY+tbQzRjKrY6SoLU1fnHISmA6DQFJWhI3/hIS6tW9SHJqahvkb2nFOPQ+IhEOh4QG0GpX9C0VSm2dmmZWv7X0T/8m0X1i6cvHsHuaH4QW1v5B12xHGmso8hjGXQAIQ/9cbTVOJoH+lPDXaB1saNDnVRVnbnb0rmBkB/kNfZ6no= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=AVMpubRv; arc=none smtp.client-ip=192.198.163.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AVMpubRv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744040986; x=1775576986; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ocKwfB6Vxkwa5A0pOC/2iu6YUSeofDIGwtON0zWaRqc=; b=AVMpubRvpRfnZ0N/RquR/RrtFZ/POLmgrzn425VcwH45bRq2AeriKcXi X3it7PwtAmZ2xHleZmyAJ6duN/he05OQcANnlnnQ2/gOzLbuSP5K0wn2l T8Ie3wcuTkogZ1gbBzhaQOHX+TGVz2FtSzwJCGpROLLXluxs1Oq79pO8U zpSGPukzDps5IBfV24rYIZwImXsOT+vQiiVBVs7DqDaeGBnANrBavq02k rRMeFfuaH7w02kOvTrro+BRO8mHGCE6boE1GBv1psoVerfGAlmrVNmm/X LvVYmIKJOlRwJkVZWqpOyzKZtC+MnkmrwxNedodMvdXtSfEHAsyOulD4V w==; X-CSE-ConnectionGUID: ryl0L6oPQTuPKj2mqpjBkA== X-CSE-MsgGUID: YkcswM17QKG6SGI3DNyQVg== X-IronPort-AV: E=McAfee;i="6700,10204,11397"; a="45555078" X-IronPort-AV: E=Sophos;i="6.15,194,1739865600"; d="scan'208";a="45555078" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2025 08:49:46 -0700 X-CSE-ConnectionGUID: MC8pyHIATC+QncCGO7ygBw== X-CSE-MsgGUID: sQ8uBaVGTxKz8/ZnJix3sg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,194,1739865600"; d="scan'208";a="158986668" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa002.jf.intel.com with ESMTP; 07 Apr 2025 08:49:43 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id BF6882E4; Mon, 07 Apr 2025 18:49:38 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Sakari Ailus , Mauro Carvalho Chehab , Tomi Valkeinen , Jai Luthra , Wolfram Sang , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Cc: Mauro Carvalho Chehab Subject: [PATCH v3 5/7] i2c: core: Do not dereference fwnode in struct device Date: Mon, 7 Apr 2025 18:45:01 +0300 Message-ID: <20250407154937.744466-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250407154937.744466-1-andriy.shevchenko@linux.intel.com> References: <20250407154937.744466-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In order to make the underneath API easier to change in the future, prevent users from dereferencing fwnode from struct device. Instead, use the specific device_set_node() API for that. Tested-by: Tomi Valkeinen Signed-off-by: Andy Shevchenko --- drivers/i2c/i2c-core-base.c | 18 ++++++++++-------- drivers/i2c/i2c-core-of.c | 1 - 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index c92badadd47a..d9e2f9559ce4 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -965,6 +965,7 @@ static void i2c_unlock_addr(struct i2c_adapter *adap, unsigned short addr, struct i2c_client * i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info) { + struct fwnode_handle *fwnode; struct i2c_client *client; bool need_put = false; int status; @@ -1005,18 +1006,19 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf client->dev.parent = &client->adapter->dev; client->dev.bus = &i2c_bus_type; client->dev.type = &i2c_client_type; - client->dev.of_node = of_node_get(info->of_node); - client->dev.fwnode = info->fwnode; device_enable_async_suspend(&client->dev); + fwnode = info->fwnode ?: of_fwnode_handle(info->of_node); + device_set_node(&client->dev, fwnode_handle_get(fwnode)); + if (info->swnode) { status = device_add_software_node(&client->dev, info->swnode); if (status) { dev_err(&adap->dev, "Failed to add software node to client %s: %d\n", client->name, status); - goto out_err_put_of_node; + goto out_err_put_fwnode; } } @@ -1035,8 +1037,8 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf out_remove_swnode: device_remove_software_node(&client->dev); need_put = true; -out_err_put_of_node: - of_node_put(info->of_node); +out_err_put_fwnode: + fwnode_handle_put(fwnode); out_err: dev_err(&adap->dev, "Failed to register i2c client %s at 0x%02x (%d)\n", @@ -1064,11 +1066,11 @@ void i2c_unregister_device(struct i2c_client *client) return; fwnode = dev_fwnode(&client->dev); - if (is_of_node(fwnode)) { + if (is_of_node(fwnode)) of_node_clear_flag(to_of_node(fwnode), OF_POPULATED); - of_node_put(client->dev.of_node); - } else if (is_acpi_device_node(fwnode)) + else if (is_acpi_device_node(fwnode)) acpi_device_clear_enumerated(to_acpi_device_node(fwnode)); + fwnode_handle_put(fwnode); device_remove_software_node(&client->dev); device_unregister(&client->dev); diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c index 02feee6c9ba9..eb7fb202355f 100644 --- a/drivers/i2c/i2c-core-of.c +++ b/drivers/i2c/i2c-core-of.c @@ -49,7 +49,6 @@ int of_i2c_get_board_info(struct device *dev, struct device_node *node, } info->addr = addr; - info->of_node = node; info->fwnode = of_fwnode_handle(node); if (of_property_read_bool(node, "host-notify"))