[From nobody Thu Jun 30 05:12:18 2016
Received: from VI1PR0401MB1869.eurprd04.prod.outlook.com (10.165.235.23) by
 HE1PR0401MB1866.eurprd04.prod.outlook.com (10.169.119.24) with Microsoft SMTP
 Server (TLS) id 15.1.528.16 via Mailbox Transport; Wed, 29 Jun 2016 11:19:34
 +0000
Received: from HE1PR0401CA0010.eurprd04.prod.outlook.com (10.166.116.148) by
 VI1PR0401MB1869.eurprd04.prod.outlook.com (10.165.235.23) with Microsoft SMTP
 Server (TLS) id 15.1.528.16; Wed, 29 Jun 2016 11:19:33 +0000
Received: from AM1FFO11FD014.protection.gbl (2a01:111:f400:7e00::115) by
 HE1PR0401CA0010.outlook.office365.com (2a01:111:e400:c512::20) with Microsoft
 SMTP Server (TLS) id 15.1.528.16 via Frontend Transport; Wed, 29 Jun 2016
 11:19:33 +0000
Received: from na01-by2-obe.outbound.protection.outlook.com (207.46.100.80) by
 AM1FFO11FD014.mail.protection.outlook.com (10.174.64.92) with
 Microsoft SMTP
 Server (TLS) id 15.1.523.9 via Frontend Transport; Wed, 29 Jun 2016 11:19:32
 +0000
Received: from BY2PR03CA039.namprd03.prod.outlook.com (10.141.249.12) by
 DM2PR0301MB0862.namprd03.prod.outlook.com (10.160.215.148) with Microsoft
 SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.523.12; Wed, 29
 Jun 2016 11:19:30 +0000
Received: from BY2FFO11FD035.protection.gbl (2a01:111:f400:7c0c::189) by
 BY2PR03CA039.outlook.office365.com (2a01:111:e400:2c5d::12) with Microsoft
 SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.528.16 via
 Frontend Transport; Wed, 29 Jun 2016 11:19:29 +0000
Received: from tx30smr01.am.freescale.net (192.88.168.50) by
 BY2FFO11FD035.mail.protection.outlook.com (10.1.14.220) with Microsoft SMTP
 Server (TLS) id 15.1.523.9 via Frontend Transport; Wed, 29 Jun 2016 11:19:28
 +0000
Received: from b27504-OptiPlex-790.ap.freescale.net
 (b27504-OptiPlex-790.ap.freescale.net [10.232.132.60])
 by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u5TBJPr5004502;
 Wed, 29 Jun 2016 04:19:26 -0700
From: Nipun Gupta &lt;nipun.gupta@nxp.com&gt;
To: &quot;gregkh@linuxfoundation.org&quot; &lt;gregkh@linuxfoundation.org&gt;, Stuart Yoder
 &lt;stuart.yoder@nxp.com&gt;
CC: &quot;devel@driverdev.osuosl.org&quot; &lt;devel@driverdev.osuosl.org&gt;,
 &quot;linux-kernel@vger.kernel.org&quot; &lt;linux-kernel@vger.kernel.org&gt;, Nipun Gupta
 &lt;nipun.gupta@nxp.com&gt;, Bharat Bhushan &lt;bharat.bhushan@nxp.com&gt;
Subject: [PATCH v2] fsl-mc: add helper macro to determine if a device is of
 fsl_mc type
Thread-Topic: [PATCH v2] fsl-mc: add helper macro to determine if a device is
 of fsl_mc type
Thread-Index: AQHR0fgdbJH4IUuCxUWjH1sx36LVvQ==
Date: Wed, 29 Jun 2016 17:14:39 +0000
Message-ID: &lt;1467220479-16864-1-git-send-email-nipun.gupta@nxp.com&gt;
Content-Language: en-US
X-MS-Exchange-Organization-AuthSource: AM1FFO11FD014.protection.gbl
X-MS-Has-Attach: 
X-MS-Exchange-Organization-Network-Message-Id: 6f53d175-ca3d-4682-1f6a-08d3a00f3ee9
X-MS-TNEF-Correlator: 
received-spf: Fail (protection.outlook.com: domain of nxp.com does not
 designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; 
 client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net;
X-Microsoft-Exchange-Diagnostics: 1; HE1PR0401MB1866;
 9:ojd5cl+OkRV4Gc5vFldJedeL9w5jC5hiuXhOLuDgL+b0QAzvk2OTk2NLekFvsxW19OLUmF+BOLTCB84LLjKa+56FGaJB7MoULCNUVzPIIresOXPX4cq+lcU5QPz6zeWI9UISW56s/GyFLe2vlUWjxaw7mCq2WKe8c88D+rlueadFRAsLIatcjGA1fGJSJPfO2z6Bz1aknuh/8c5p9hnL8w==
Content-Type: text/plain; charset=&quot;iso-8859-1&quot;
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

Add a helper macro to return if a device has a bus type of fsl_mc.
This makes the bus driver code more readable and provides a way for
drivers like the SMMU driver to easily check the bus type.

Signed-off-by: Nipun Gupta &lt;nipun.gupta@nxp.com&gt;
Signed-off-by: Bharat Bhushan &lt;bharat.bhushan@nxp.com&gt;
---
 drivers/staging/fsl-mc/bus/dprc-driver.c               | 4 ++--
 drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c | 2 +-
 drivers/staging/fsl-mc/bus/mc-allocator.c              | 6 +++---
 drivers/staging/fsl-mc/bus/mc-bus.c                    | 6 +++---
 drivers/staging/fsl-mc/include/mc.h                    | 7 +++++++
 5 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl=
-mc/bus/dprc-driver.c
index 7fc4717..cd6d75a 100644
--- a/drivers/staging/fsl-mc/bus/dprc-driver.c
+++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
@@ -649,7 +649,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
                /*
                 * This is a child DPRC:
                 */
-               if (WARN_ON(parent_dev-&gt;bus !=3D &amp;fsl_mc_bus_type))
+               if (WARN_ON(!dev_is_fsl_mc(parent_dev)))
                        return -EINVAL;

                if (WARN_ON(mc_dev-&gt;obj_desc.region_count =3D=3D 0))
@@ -681,7 +681,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
                 */
                struct irq_domain *mc_msi_domain;

-               if (WARN_ON(parent_dev-&gt;bus =3D=3D &amp;fsl_mc_bus_type))
+               if (WARN_ON(dev_is_fsl_mc(parent_dev)))
                        return -EINVAL;

                error =3D fsl_mc_find_msi_domain(parent_dev,
diff --git a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c b/drive=
rs/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
index 720e2b0..d0c20d6 100644
--- a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
+++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
@@ -35,7 +35,7 @@ static int its_fsl_mc_msi_prepare(struct irq_domain *msi_=
domain,
        struct fsl_mc_device *mc_bus_dev;
        struct msi_domain_info *msi_info;

-       if (WARN_ON(dev-&gt;bus !=3D &amp;fsl_mc_bus_type))
+       if (WARN_ON(!dev_is_fsl_mc(dev)))
                return -EINVAL;

        mc_bus_dev =3D to_fsl_mc_device(dev);
diff --git a/drivers/staging/fsl-mc/bus/mc-allocator.c b/drivers/staging/fs=
l-mc/bus/mc-allocator.c
index fb08f22..9216c32 100644
--- a/drivers/staging/fsl-mc/bus/mc-allocator.c
+++ b/drivers/staging/fsl-mc/bus/mc-allocator.c
@@ -281,7 +281,7 @@ int __must_check fsl_mc_portal_allocate(struct fsl_mc_d=
evice *mc_dev,
        if (mc_dev-&gt;flags &amp; FSL_MC_IS_DPRC) {
                mc_bus_dev =3D mc_dev;
        } else {
-               if (WARN_ON(mc_dev-&gt;dev.parent-&gt;bus !=3D &amp;fsl_mc_bus_type))
+               if (WARN_ON(!dev_is_fsl_mc(mc_dev-&gt;dev.parent)))
                        return error;

                mc_bus_dev =3D to_fsl_mc_device(mc_dev-&gt;dev.parent);
@@ -420,7 +420,7 @@ int __must_check fsl_mc_object_allocate(struct fsl_mc_d=
evice *mc_dev,
        if (WARN_ON(mc_dev-&gt;flags &amp; FSL_MC_IS_DPRC))
                goto error;

-       if (WARN_ON(mc_dev-&gt;dev.parent-&gt;bus !=3D &amp;fsl_mc_bus_type))
+       if (WARN_ON(!dev_is_fsl_mc(mc_dev-&gt;dev.parent)))
                goto error;

        if (WARN_ON(pool_type =3D=3D FSL_MC_POOL_DPMCP))
@@ -678,7 +678,7 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device =
*mc_dev)
                return -EINVAL;

        mc_bus_dev =3D to_fsl_mc_device(mc_dev-&gt;dev.parent);
-       if (WARN_ON(mc_bus_dev-&gt;dev.bus !=3D &amp;fsl_mc_bus_type))
+       if (WARN_ON(!dev_is_fsl_mc(&amp;mc_bus_dev-&gt;dev)))
                return -EINVAL;

        mc_bus =3D to_fsl_mc_bus(mc_bus_dev);
diff --git a/drivers/staging/fsl-mc/bus/mc-bus.c b/drivers/staging/fsl-mc/b=
us/mc-bus.c
index 4053643..098f07c 100644
--- a/drivers/staging/fsl-mc/bus/mc-bus.c
+++ b/drivers/staging/fsl-mc/bus/mc-bus.c
@@ -207,11 +207,11 @@ static void fsl_mc_get_root_dprc(struct device *dev,
 {
        if (WARN_ON(!dev)) {
                *root_dprc_dev =3D NULL;
-       } else if (WARN_ON(dev-&gt;bus !=3D &amp;fsl_mc_bus_type)) {
+       } else if (WARN_ON(!dev_is_fsl_mc(dev))) {
                *root_dprc_dev =3D NULL;
        } else {
                *root_dprc_dev =3D dev;
-               while ((*root_dprc_dev)-&gt;parent-&gt;bus =3D=3D &amp;fsl_mc_bus_typ=
e)
+               while (dev_is_fsl_mc((*root_dprc_dev)-&gt;parent))
                        *root_dprc_dev =3D (*root_dprc_dev)-&gt;parent;
        }
 }
@@ -405,7 +405,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
        struct fsl_mc_bus *mc_bus =3D NULL;
        struct fsl_mc_device *parent_mc_dev;

-       if (parent_dev-&gt;bus =3D=3D &amp;fsl_mc_bus_type)
+       if (dev_is_fsl_mc(parent_dev))
                parent_mc_dev =3D to_fsl_mc_device(parent_dev);
        else
                parent_mc_dev =3D NULL;
diff --git a/drivers/staging/fsl-mc/include/mc.h b/drivers/staging/fsl-mc/i=
nclude/mc.h
index ac7c1ce..91213f5 100644
--- a/drivers/staging/fsl-mc/include/mc.h
+++ b/drivers/staging/fsl-mc/include/mc.h
@@ -183,6 +183,13 @@ struct fsl_mc_device {
 #define to_fsl_mc_device(_dev) \
        container_of(_dev, struct fsl_mc_device, dev)

+#ifdef CONFIG_FSL_MC_BUS
+#define dev_is_fsl_mc(_dev) ((_dev)-&gt;bus =3D=3D &amp;fsl_mc_bus_type)
+#else
+/* If fsl-mc bus is not present device cannot belong to fsl-mc bus */
+#define dev_is_fsl_mc(_dev) (0)
+#endif
+
 /*
  * module_fsl_mc_driver() - Helper macro for drivers that don't do
  * anything special in module init/exit.  This eliminates a lot of
--
1.9.1

]