[PATCH 2/3] net: qrtr: Define macro to convert QMI version and instance to QRTR instance

Yassine Oudjana posted 3 patches 10 months, 1 week ago
There is a newer version of this series
[PATCH 2/3] net: qrtr: Define macro to convert QMI version and instance to QRTR instance
Posted by Yassine Oudjana 10 months, 1 week ago
Move QRTR instance conversion from qmi_interface into a new macro in order
to reuse it in QRTR device ID tables.

Signed-off-by: Yassine Oudjana <y.oudjana@protonmail.com>
---
 drivers/soc/qcom/qmi_interface.c | 5 +++--
 include/linux/soc/qcom/qrtr.h    | 2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/soc/qcom/qmi_interface.c b/drivers/soc/qcom/qmi_interface.c
index bc6d6379d8b1..cb57b7e1f252 100644
--- a/drivers/soc/qcom/qmi_interface.c
+++ b/drivers/soc/qcom/qmi_interface.c
@@ -14,6 +14,7 @@
 #include <linux/workqueue.h>
 #include <trace/events/sock.h>
 #include <linux/soc/qcom/qmi.h>
+#include <linux/soc/qcom/qrtr.h>
 
 static struct socket *qmi_sock_create(struct qmi_handle *qmi,
 				      struct sockaddr_qrtr *sq);
@@ -173,7 +174,7 @@ static void qmi_send_new_lookup(struct qmi_handle *qmi, struct qmi_service *svc)
 	memset(&pkt, 0, sizeof(pkt));
 	pkt.cmd = cpu_to_le32(QRTR_TYPE_NEW_LOOKUP);
 	pkt.server.service = cpu_to_le32(svc->service);
-	pkt.server.instance = cpu_to_le32(svc->version | svc->instance << 8);
+	pkt.server.instance = cpu_to_le32(QRTR_INSTANCE(svc->version, svc->instance));
 
 	sq.sq_family = qmi->sq.sq_family;
 	sq.sq_node = qmi->sq.sq_node;
@@ -236,7 +237,7 @@ static void qmi_send_new_server(struct qmi_handle *qmi, struct qmi_service *svc)
 	memset(&pkt, 0, sizeof(pkt));
 	pkt.cmd = cpu_to_le32(QRTR_TYPE_NEW_SERVER);
 	pkt.server.service = cpu_to_le32(svc->service);
-	pkt.server.instance = cpu_to_le32(svc->version | svc->instance << 8);
+	pkt.server.instance = cpu_to_le32(QRTR_INSTANCE(svc->version, svc->instance));
 	pkt.server.node = cpu_to_le32(qmi->sq.sq_node);
 	pkt.server.port = cpu_to_le32(qmi->sq.sq_port);
 
diff --git a/include/linux/soc/qcom/qrtr.h b/include/linux/soc/qcom/qrtr.h
index 4d7f25c64c56..10c89a35cbb9 100644
--- a/include/linux/soc/qcom/qrtr.h
+++ b/include/linux/soc/qcom/qrtr.h
@@ -13,6 +13,8 @@ struct qrtr_device {
 
 #define to_qrtr_device(d) container_of(d, struct qrtr_device, dev)
 
+#define QRTR_INSTANCE(qmi_version, qmi_instance) (qmi_version | qmi_instance << 8)
+
 struct qrtr_driver {
 	int (*probe)(struct qrtr_device *qdev);
 	void (*remove)(struct qrtr_device *qdev);
-- 
2.49.0
Re: [PATCH 2/3] net: qrtr: Define macro to convert QMI version and instance to QRTR instance
Posted by Konrad Dybcio 10 months ago
On 4/6/25 4:07 PM, Yassine Oudjana wrote:
> Move QRTR instance conversion from qmi_interface into a new macro in order
> to reuse it in QRTR device ID tables.
> 
> Signed-off-by: Yassine Oudjana <y.oudjana@protonmail.com>
> ---
>  drivers/soc/qcom/qmi_interface.c | 5 +++--
>  include/linux/soc/qcom/qrtr.h    | 2 ++
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/soc/qcom/qmi_interface.c b/drivers/soc/qcom/qmi_interface.c
> index bc6d6379d8b1..cb57b7e1f252 100644
> --- a/drivers/soc/qcom/qmi_interface.c
> +++ b/drivers/soc/qcom/qmi_interface.c
> @@ -14,6 +14,7 @@
>  #include <linux/workqueue.h>
>  #include <trace/events/sock.h>
>  #include <linux/soc/qcom/qmi.h>
> +#include <linux/soc/qcom/qrtr.h>
>  
>  static struct socket *qmi_sock_create(struct qmi_handle *qmi,
>  				      struct sockaddr_qrtr *sq);
> @@ -173,7 +174,7 @@ static void qmi_send_new_lookup(struct qmi_handle *qmi, struct qmi_service *svc)
>  	memset(&pkt, 0, sizeof(pkt));
>  	pkt.cmd = cpu_to_le32(QRTR_TYPE_NEW_LOOKUP);
>  	pkt.server.service = cpu_to_le32(svc->service);
> -	pkt.server.instance = cpu_to_le32(svc->version | svc->instance << 8);
> +	pkt.server.instance = cpu_to_le32(QRTR_INSTANCE(svc->version, svc->instance));
>  
>  	sq.sq_family = qmi->sq.sq_family;
>  	sq.sq_node = qmi->sq.sq_node;
> @@ -236,7 +237,7 @@ static void qmi_send_new_server(struct qmi_handle *qmi, struct qmi_service *svc)
>  	memset(&pkt, 0, sizeof(pkt));
>  	pkt.cmd = cpu_to_le32(QRTR_TYPE_NEW_SERVER);
>  	pkt.server.service = cpu_to_le32(svc->service);
> -	pkt.server.instance = cpu_to_le32(svc->version | svc->instance << 8);
> +	pkt.server.instance = cpu_to_le32(QRTR_INSTANCE(svc->version, svc->instance));
>  	pkt.server.node = cpu_to_le32(qmi->sq.sq_node);
>  	pkt.server.port = cpu_to_le32(qmi->sq.sq_port);
>  
> diff --git a/include/linux/soc/qcom/qrtr.h b/include/linux/soc/qcom/qrtr.h
> index 4d7f25c64c56..10c89a35cbb9 100644
> --- a/include/linux/soc/qcom/qrtr.h
> +++ b/include/linux/soc/qcom/qrtr.h
> @@ -13,6 +13,8 @@ struct qrtr_device {
>  
>  #define to_qrtr_device(d) container_of(d, struct qrtr_device, dev)
>  
> +#define QRTR_INSTANCE(qmi_version, qmi_instance) (qmi_version | qmi_instance << 8)

Please use FIELD_PREP + GENMASK to avoid potential overflows

Konrad
Re: [PATCH 2/3] net: qrtr: Define macro to convert QMI version and instance to QRTR instance
Posted by Yassine Oudjana 7 months, 1 week ago
On Wednesday, April 9th, 2025 at 3:54 PM, Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> wrote:

> On 4/6/25 4:07 PM, Yassine Oudjana wrote:
> 
> > Move QRTR instance conversion from qmi_interface into a new macro in order
> > to reuse it in QRTR device ID tables.
> > 
> > Signed-off-by: Yassine Oudjana y.oudjana@protonmail.com
> > ---
> > drivers/soc/qcom/qmi_interface.c | 5 +++--
> > include/linux/soc/qcom/qrtr.h | 2 ++
> > 2 files changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/soc/qcom/qmi_interface.c b/drivers/soc/qcom/qmi_interface.c
> > index bc6d6379d8b1..cb57b7e1f252 100644
> > --- a/drivers/soc/qcom/qmi_interface.c
> > +++ b/drivers/soc/qcom/qmi_interface.c
> > @@ -14,6 +14,7 @@
> > #include <linux/workqueue.h>
> > #include <trace/events/sock.h>
> > #include <linux/soc/qcom/qmi.h>
> > +#include <linux/soc/qcom/qrtr.h>
> > 
> > static struct socket *qmi_sock_create(struct qmi_handle *qmi,
> > struct sockaddr_qrtr *sq);
> > @@ -173,7 +174,7 @@ static void qmi_send_new_lookup(struct qmi_handle *qmi, struct qmi_service *svc)
> > memset(&pkt, 0, sizeof(pkt));
> > pkt.cmd = cpu_to_le32(QRTR_TYPE_NEW_LOOKUP);
> > pkt.server.service = cpu_to_le32(svc->service);
> > - pkt.server.instance = cpu_to_le32(svc->version | svc->instance << 8);
> > + pkt.server.instance = cpu_to_le32(QRTR_INSTANCE(svc->version, svc->instance));
> > 
> > sq.sq_family = qmi->sq.sq_family;
> > sq.sq_node = qmi->sq.sq_node;
> > @@ -236,7 +237,7 @@ static void qmi_send_new_server(struct qmi_handle *qmi, struct qmi_service *svc)
> > memset(&pkt, 0, sizeof(pkt));
> > pkt.cmd = cpu_to_le32(QRTR_TYPE_NEW_SERVER);
> > pkt.server.service = cpu_to_le32(svc->service);
> > - pkt.server.instance = cpu_to_le32(svc->version | svc->instance << 8);
> > + pkt.server.instance = cpu_to_le32(QRTR_INSTANCE(svc->version, svc->instance));
> > pkt.server.node = cpu_to_le32(qmi->sq.sq_node);
> > pkt.server.port = cpu_to_le32(qmi->sq.sq_port);
> > 
> > diff --git a/include/linux/soc/qcom/qrtr.h b/include/linux/soc/qcom/qrtr.h
> > index 4d7f25c64c56..10c89a35cbb9 100644
> > --- a/include/linux/soc/qcom/qrtr.h
> > +++ b/include/linux/soc/qcom/qrtr.h
> > @@ -13,6 +13,8 @@ struct qrtr_device {
> > 
> > #define to_qrtr_device(d) container_of(d, struct qrtr_device, dev)
> > 
> > +#define QRTR_INSTANCE(qmi_version, qmi_instance) (qmi_version | qmi_instance << 8)
> 
> 
> Please use FIELD_PREP + GENMASK to avoid potential overflows
> 
> Konrad

Since I'm using this macro in initializing QRTR match tables I am unable to use
FIELD_PREP. When I do, I get such errors:

In file included from ../arch/arm64/include/asm/sysreg.h:1108,
                 from ../arch/arm64/include/asm/memory.h:223,
                 from ../arch/arm64/include/asm/pgtable-prot.h:8,
                 from ../arch/arm64/include/asm/sparsemem.h:8,
                 from ../include/linux/numa.h:23,
                 from ../include/linux/cpumask.h:17,
                 from ../include/linux/smp.h:13,
                 from ../include/linux/lockdep.h:14,
                 from ../include/linux/mutex.h:17,
                 from ../include/linux/kernfs.h:11,
                 from ../include/linux/sysfs.h:16,
                 from ../include/linux/iio/buffer.h:9,
                 from ../drivers/iio/common/qcom_smgr/qcom_smgr.c:8:
../include/linux/bitfield.h:114:9: error: braced-group within expression allowed only inside a function
  114 |         ({                                                              \
      |         ^
../include/linux/soc/qcom/qrtr.h:21:10: note: in expansion of macro 'FIELD_PREP'
   21 |         (FIELD_PREP(GENMASK(7, 0), qmi_version) | FIELD_PREP(GENMASK(15, 8), qmi_instance))
      |          ^~~~~~~~~~
../drivers/iio/common/qcom_smgr/qcom_smgr.c:825:29: note: in expansion of macro 'QRTR_INSTANCE'
  825 |                 .instance = QRTR_INSTANCE(SNS_SMGR_QMI_SVC_V1,
      |                             ^~~~~~~~~~~~~
../include/linux/bitfield.h:114:9: error: braced-group within expression allowed only inside a function
  114 |         ({                                                              \
      |         ^
../include/linux/soc/qcom/qrtr.h:21:51: note: in expansion of macro 'FIELD_PREP'
   21 |         (FIELD_PREP(GENMASK(7, 0), qmi_version) | FIELD_PREP(GENMASK(15, 8), qmi_instance))
      |                                                   ^~~~~~~~~~
../drivers/iio/common/qcom_smgr/qcom_smgr.c:825:29: note: in expansion of macro 'QRTR_INSTANCE'
  825 |                 .instance = QRTR_INSTANCE(SNS_SMGR_QMI_SVC_V1,
      |                             ^~~~~~~~~~~~~
Re: [PATCH 2/3] net: qrtr: Define macro to convert QMI version and instance to QRTR instance
Posted by Simon Horman 7 months, 1 week ago
On Sat, Jul 05, 2025 at 06:29:39PM +0000, Yassine Oudjana wrote:
> On Wednesday, April 9th, 2025 at 3:54 PM, Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> wrote:
> 
> > On 4/6/25 4:07 PM, Yassine Oudjana wrote:

...

> > > diff --git a/include/linux/soc/qcom/qrtr.h b/include/linux/soc/qcom/qrtr.h
> > > index 4d7f25c64c56..10c89a35cbb9 100644
> > > --- a/include/linux/soc/qcom/qrtr.h
> > > +++ b/include/linux/soc/qcom/qrtr.h
> > > @@ -13,6 +13,8 @@ struct qrtr_device {
> > > 
> > > #define to_qrtr_device(d) container_of(d, struct qrtr_device, dev)
> > > 
> > > +#define QRTR_INSTANCE(qmi_version, qmi_instance) (qmi_version | qmi_instance << 8)
> > 
> > 
> > Please use FIELD_PREP + GENMASK to avoid potential overflows
> > 
> > Konrad
> 
> Since I'm using this macro in initializing QRTR match tables I am unable to use
> FIELD_PREP. When I do, I get such errors:

Does using FIELD_PREP_CONST, say in a QRTR_INSTANCE_CONST variant, help?

> 
> In file included from ../arch/arm64/include/asm/sysreg.h:1108,
>                  from ../arch/arm64/include/asm/memory.h:223,
>                  from ../arch/arm64/include/asm/pgtable-prot.h:8,
>                  from ../arch/arm64/include/asm/sparsemem.h:8,
>                  from ../include/linux/numa.h:23,
>                  from ../include/linux/cpumask.h:17,
>                  from ../include/linux/smp.h:13,
>                  from ../include/linux/lockdep.h:14,
>                  from ../include/linux/mutex.h:17,
>                  from ../include/linux/kernfs.h:11,
>                  from ../include/linux/sysfs.h:16,
>                  from ../include/linux/iio/buffer.h:9,
>                  from ../drivers/iio/common/qcom_smgr/qcom_smgr.c:8:
> ../include/linux/bitfield.h:114:9: error: braced-group within expression allowed only inside a function
>   114 |         ({                                                              \
>       |         ^
> ../include/linux/soc/qcom/qrtr.h:21:10: note: in expansion of macro 'FIELD_PREP'
>    21 |         (FIELD_PREP(GENMASK(7, 0), qmi_version) | FIELD_PREP(GENMASK(15, 8), qmi_instance))
>       |          ^~~~~~~~~~
> ../drivers/iio/common/qcom_smgr/qcom_smgr.c:825:29: note: in expansion of macro 'QRTR_INSTANCE'
>   825 |                 .instance = QRTR_INSTANCE(SNS_SMGR_QMI_SVC_V1,
>       |                             ^~~~~~~~~~~~~

...
Re: [PATCH 2/3] net: qrtr: Define macro to convert QMI version and instance to QRTR instance
Posted by Yassine Oudjana 7 months ago




Sent with Proton Mail secure email.

On Monday, July 7th, 2025 at 6:06 PM, Simon Horman <horms@kernel.org> wrote:

> On Sat, Jul 05, 2025 at 06:29:39PM +0000, Yassine Oudjana wrote:
> 
> > On Wednesday, April 9th, 2025 at 3:54 PM, Konrad Dybcio konrad.dybcio@oss.qualcomm.com wrote:
> > 
> > > On 4/6/25 4:07 PM, Yassine Oudjana wrote:
> 
> 
> ...
> 
> > > > diff --git a/include/linux/soc/qcom/qrtr.h b/include/linux/soc/qcom/qrtr.h
> > > > index 4d7f25c64c56..10c89a35cbb9 100644
> > > > --- a/include/linux/soc/qcom/qrtr.h
> > > > +++ b/include/linux/soc/qcom/qrtr.h
> > > > @@ -13,6 +13,8 @@ struct qrtr_device {
> > > > 
> > > > #define to_qrtr_device(d) container_of(d, struct qrtr_device, dev)
> > > > 
> > > > +#define QRTR_INSTANCE(qmi_version, qmi_instance) (qmi_version | qmi_instance << 8)
> > > 
> > > Please use FIELD_PREP + GENMASK to avoid potential overflows
> > > 
> > > Konrad
> > 
> > Since I'm using this macro in initializing QRTR match tables I am unable to use
> > FIELD_PREP. When I do, I get such errors:
> 
> 
> Does using FIELD_PREP_CONST, say in a QRTR_INSTANCE_CONST variant, help?

That works, but do we want to have two variants? Or in this case maybe
I should leave qmi_interface.c untouched and define the macro only for use
in match tables?

> 
> > In file included from ../arch/arm64/include/asm/sysreg.h:1108,
> > from ../arch/arm64/include/asm/memory.h:223,
> > from ../arch/arm64/include/asm/pgtable-prot.h:8,
> > from ../arch/arm64/include/asm/sparsemem.h:8,
> > from ../include/linux/numa.h:23,
> > from ../include/linux/cpumask.h:17,
> > from ../include/linux/smp.h:13,
> > from ../include/linux/lockdep.h:14,
> > from ../include/linux/mutex.h:17,
> > from ../include/linux/kernfs.h:11,
> > from ../include/linux/sysfs.h:16,
> > from ../include/linux/iio/buffer.h:9,
> > from ../drivers/iio/common/qcom_smgr/qcom_smgr.c:8:
> > ../include/linux/bitfield.h:114:9: error: braced-group within expression allowed only inside a function
> > 114 | ({ \
> > | ^
> > ../include/linux/soc/qcom/qrtr.h:21:10: note: in expansion of macro 'FIELD_PREP'
> > 21 | (FIELD_PREP(GENMASK(7, 0), qmi_version) | FIELD_PREP(GENMASK(15, 8), qmi_instance))
> > | ^~~~~~~~~~
> > ../drivers/iio/common/qcom_smgr/qcom_smgr.c:825:29: note: in expansion of macro 'QRTR_INSTANCE'
> > 825 | .instance = QRTR_INSTANCE(SNS_SMGR_QMI_SVC_V1,
> > | ^~~~~~~~~~~~~
> 
> 
> ...
Re: [PATCH 2/3] net: qrtr: Define macro to convert QMI version and instance to QRTR instance
Posted by Simon Horman 7 months ago
On Wed, Jul 09, 2025 at 07:44:49AM +0000, Yassine Oudjana wrote:
> 
> 
> 
> 
> 
> Sent with Proton Mail secure email.
> 
> On Monday, July 7th, 2025 at 6:06 PM, Simon Horman <horms@kernel.org> wrote:
> 
> > On Sat, Jul 05, 2025 at 06:29:39PM +0000, Yassine Oudjana wrote:
> > 
> > > On Wednesday, April 9th, 2025 at 3:54 PM, Konrad Dybcio konrad.dybcio@oss.qualcomm.com wrote:
> > > 
> > > > On 4/6/25 4:07 PM, Yassine Oudjana wrote:
> > 
> > 
> > ...
> > 
> > > > > diff --git a/include/linux/soc/qcom/qrtr.h b/include/linux/soc/qcom/qrtr.h
> > > > > index 4d7f25c64c56..10c89a35cbb9 100644
> > > > > --- a/include/linux/soc/qcom/qrtr.h
> > > > > +++ b/include/linux/soc/qcom/qrtr.h
> > > > > @@ -13,6 +13,8 @@ struct qrtr_device {
> > > > > 
> > > > > #define to_qrtr_device(d) container_of(d, struct qrtr_device, dev)
> > > > > 
> > > > > +#define QRTR_INSTANCE(qmi_version, qmi_instance) (qmi_version | qmi_instance << 8)
> > > > 
> > > > Please use FIELD_PREP + GENMASK to avoid potential overflows
> > > > 
> > > > Konrad
> > > 
> > > Since I'm using this macro in initializing QRTR match tables I am unable to use
> > > FIELD_PREP. When I do, I get such errors:
> > 
> > 
> > Does using FIELD_PREP_CONST, say in a QRTR_INSTANCE_CONST variant, help?
> 
> That works, but do we want to have two variants? Or in this case maybe
> I should leave qmi_interface.c untouched and define the macro only for use
> in match tables?

FWIIW, my order of preference would be:

1. Two variants, declared next to each other
2. One variant (using FIELD_PREP_CONST)
3. Leave qmi_interface.c untouched

...