Skip to contentSkip to conversation

sdio: About pointers in sdio_device_id::driver_data

PATCH In review Uwe Kleine-König (The Capable Hub) 9 participants 23 messages Apr 17 – May 26

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover sdio: About pointers in sdio_device_id::driver_data

<linux/mod_devicetable.h> contains several device_id structs for various device types.

Most of them have one of:

- kernel_ulong_t driver_data (sometimes called "driver_info")
- unsigned long driver_data
- const void *data (sometimes called "driver_data" or "context", sometimes not const)

Taking sdio_device_id as an arbitrary[1] example (which has kernel_ulong_t driver_data), there are drivers that store integer values in it (e.g. drivers/media/mmc/siano/smssdio.c) and others use pointers (e.g. drivers/net/wireless/realtek/rtw88/rtw8723ds.c). The latter involves explicit casting, both for initialisation and for usage.

In the past I tried to address this using i2c as discussion case[2]. Back then the motivation was just to get rid of the ugly casts. Today I'm working on CHERI which is an architecture extension (currently for arm and riscv) that uses 128 bit pointers to store additional information, implementing e.g. read-only pointers and preventing out of bounds access on the hardware level.

The complication here is that a kernel_ulong_t (which is still 64 bit with CHERI) cannot store a pointer.

The obvious way to fix that is to replace the kernel_ulong_t by an anonymous union that contains the original unsigned long and a pointer. This doesn't change the size (or layout) of the device id struct for archs where sizeof(long) >= sizeof(void *) [3] and gets rid of the casting. On CHERI archs this is an ABI change, but as a new architecture changing ABI isn't an issue there.

I was surprised that changing struct sdio_device_id didn't require preparation in the various drivers as they all already use named initializers.

So the first patch expands struct sdio_device_id and the 5 following patches implement cleanups that can be done then.

Patches 2 to 6 all depend on the first patch (only). This is not urgent and thus merge window material. I guess merging of this series has to happen in 3 steps:

1) patch #1 via mmc
2) patches #2 and #3 via bluetooth
3) patches #4 - #6 via wireless

(where 2) and 3) are independent).

The series was build tested on arm64.

[1] well, one that isn't used as much as spi_device_id or i2c_device_id to have get a manageable POC.
[2] https://lore.kernel.org/lkml/[email protected]
[3] As of now this is true on all architectures running Linux even with s/>=/==/

Uwe Kleine-König (The Capable Hub) (6):
sdio: Add syntactic sugar to store a pointer in sdio_driver_id
Bluetooth: btmrvl_sdio: Make use of driver data pointer in
sdio_device_id
Bluetooth: btmtksdio: Make use of driver data pointer in
sdio_device_id
wifi: rtw88: Benefit from sdio_device_id::driver_data_ptr
wifi: mt76: mt7921-sdio: Make use of driver data pointer in
sdio_device_id
wifi: mwifiex: Make use of driver data pointer in sdio_device_id

 drivers/bluetooth/btmrvl_sdio.c               | 22 ++++++++---------
 drivers/bluetooth/btmtksdio.c                 |  8 +++----
 drivers/net/wireless/marvell/mwifiex/sdio.c   | 24 +++++++++----------
 .../net/wireless/mediatek/mt76/mt7921/sdio.c  |  4 ++--
 drivers/net/wireless/mediatek/mt76/mt792x.h   |  2 +-
 .../net/wireless/mediatek/mt76/mt792x_core.c  |  2 +-
 .../net/wireless/realtek/rtw88/rtw8723cs.c    |  2 +-
 .../net/wireless/realtek/rtw88/rtw8723ds.c    |  4 ++--
 .../net/wireless/realtek/rtw88/rtw8821cs.c    |  2 +-
 .../net/wireless/realtek/rtw88/rtw8822bs.c    |  2 +-
 .../net/wireless/realtek/rtw88/rtw8822cs.c    |  2 +-
 drivers/net/wireless/realtek/rtw88/sdio.c     |  2 +-
 include/linux/mod_devicetable.h               |  5 +++-
 13 files changed, 42 insertions(+), 39 deletions(-)

base-commit: 028ef9c96e96197026887c0f092424679298aae8

Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/6 sdio: Add syntactic sugar to store a pointer in sdio_driver_id

On all current Linux architectures sizeof(long) == sizeof(void *) and this is used a lot through the kernel. For example it enables the usual practice to store pointers in sdio_driver_id's .driver_data member.

This works fine, but involves casting and thus isn't type-safe. Additionally with the CHERI architecture extension there are machines with sizeof(void *) > sizeof(long) for with the traditional approach of storing a pointer in .driver_data doesn't work.

By replacing the plain unsigned long .driver_data by an anonymous union, most of the casting can be dropped and it yields a working solution for CHERI.

All users of struct sdio_driver_id are initialized in a way that is compatible with the new definition, so no adaptions are needed there.

---
 include/linux/mod_devicetable.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/linux/mod_devicetable.h +4 -1
index 5b1725fe9707..0eb5d196f5b5 100644
@@ -414,7 +414,10 @@ struct sdio_device_id {
 	__u8	class;			/* Standard interface or SDIO_ANY_ID */
 	__u16	vendor;			/* Vendor or SDIO_ANY_ID */
 	__u16	device;			/* Device ID or SDIO_ANY_ID */
-	kernel_ulong_t driver_data;	/* Data private to the driver */
+	union {				/* Data private to the driver */
+		kernel_ulong_t driver_data;
+		const void *driver_data_ptr;
+	};
 };
 
 /* SSB core, see drivers/ssb/ */
Signature · 1 line
2.47.3
#2 lore raw

This is an automated email and please do not reply to this email.

Dear Submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.

----- Output -----

error: patch failed: drivers/bluetooth/btmtksdio.c:64
error: drivers/bluetooth/btmtksdio.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch

Please resolve the issue and submit the patches again.

---
Regards,
Linux Bluetooth

#3 lore raw

Hello,

some feedback for this mail:

Quoted 1 line · On Fri, Apr 17, 2026 at 07:11:42AM -0700, [email protected] wrote:

This is an automated email and please do not reply to this email.

I hope it's ok to ignore this request here :-)

Quoted 1 line

While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.

It would be great to point out the URL and commit hash of this current HEAD to simplify acting on that and also be able to understand the details of the mail in a few weeks when the repository probably got a few more commits.

Having said that, the patch series fits on top of
git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git's
HEAD currently at bc39a094730c ("Bluetooth: hci_sync: fix stack buffer overflow in hci_le_big_create_sync"). But I guess "the repository" is
git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git
that indeed contains a conflicting commit.

Assuming that the series being applicable to the bluetooth HEAD isn't the only test done here, a great way to make the bot reply more useful would be to honor

	base-commit: 028ef9c96e96197026887c0f092424679298aae8

from the cover letter and then provide more test results (after pointing out that the wrong base was chosen).

Quoted 7 lines

----- Output -----

error: patch failed: drivers/bluetooth/btmtksdio.c:64
error: drivers/bluetooth/btmtksdio.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch

Please resolve the issue and submit the patches again.

Given that the bluetooth parts are not ready for application now without the first patch in the series, I won't do that now.

Best regards
Uwe

#4 lore raw

Re: [PATCH v1 1/6] sdio: Add syntactic sugar to store a pointer in sdio_driver_id

In reply to Uwe Kleine-König (The Capable Hub)

Hello,

Quoted 9 lines · Uwe Kleine-König (The Capable Hub)

On all current Linux architectures sizeof(long) == sizeof(void *) and this is used a lot through the kernel. For example it enables the usual practice to store pointers in sdio_driver_id's .driver_data member.

This works fine, but involves casting and thus isn't type-safe. Additionally with the CHERI architecture extension there are machines with sizeof(void *) > sizeof(long) for with the traditional approach of storing a pointer in .driver_data doesn't work.

Quoted 6 lines

By replacing the plain unsigned long .driver_data by an anonymous union, most of the casting can be dropped and it yields a working solution for CHERI.

All users of struct sdio_driver_id are initialized in a way that is compatible with the new definition, so no adaptions are needed there.

sashiko.dev found s/sdio_driver_id/sdio_device_id/ twice in the commit log and once in the short log. If you consider applying this patch please adapt the commit message accordingly.

Many thanks to those who created sashiko.dev!

Best regards
Uwe

#5 lore raw

Re: [PATCH v1 1/6] sdio: Add syntactic sugar to store a pointer in sdio_driver_id

Hi Uwe,

Quoted 17 lines · Uwe Kleine-König (The Capable Hub)

Hello,

Quoted 13 lines · Uwe Kleine-König (The Capable Hub)

On all current Linux architectures sizeof(long) == sizeof(void *) and this is used a lot through the kernel. For example it enables the usual practice to store pointers in sdio_driver_id's .driver_data member.

This works fine, but involves casting and thus isn't type-safe. Additionally with the CHERI architecture extension there are machines with sizeof(void *) > sizeof(long) for with the traditional approach of storing a pointer in .driver_data doesn't work.

By replacing the plain unsigned long .driver_data by an anonymous union, most of the casting can be dropped and it yields a working solution for CHERI.

Quoted 6 lines
Quoted 2 lines

All users of struct sdio_driver_id are initialized in a way that is compatible with the new definition, so no adaptions are needed there.

sashiko.dev found s/sdio_driver_id/sdio_device_id/ twice in the commit log and once in the short log. If you consider applying this patch please adapt the commit message accordingly.

No problem I can fix them up once applying.

Quoted 4 lines

Many thanks to those who created sashiko.dev!

Best regards
Uwe

We only received 1-3 of the 6:

https://patchwork.kernel.org/project/bluetooth/list/?series=1082520

Or is this on purpose, and we should consider the set complete?

Signature · 1 line
Luiz Augusto von Dentz
#6 lore raw

Re: [PATCH v1 1/6] sdio: Add syntactic sugar to store a pointer in sdio_driver_id

Hello Luiz,

Quoted 8 lines · Luiz Augusto von Dentz
Quoted 6 lines · Uwe Kleine-König (The Capable Hub)
Quoted 5 lines · Uwe Kleine-König (The Capable Hub)

On all current Linux architectures sizeof(long) == sizeof(void *) and this is used a lot through the kernel. For example it enables the usual practice to store pointers in sdio_driver_id's .driver_data member.

This works fine, but involves casting and thus isn't type-safe.

To be honest, with the involved void* this isn't really type-safe either, but at least the data keeps being a pointer which is really helpful on CHERI. FTR: The alternative would be to use uintptr_t instead of unsigned long, which also has proponents in the CHERI community and which is used in the current vendor patch stack.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Additionally with the CHERI architecture extension there are machines with sizeof(void *) > sizeof(long) for with the traditional approach of storing a pointer in .driver_data doesn't work.

By replacing the plain unsigned long .driver_data by an anonymous union, most of the casting can be dropped and it yields a working solution for CHERI.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

All users of struct sdio_driver_id are initialized in a way that is compatible with the new definition, so no adaptions are needed there.

sashiko.dev found s/sdio_driver_id/sdio_device_id/ twice in the commit log and once in the short log. If you consider applying this patch please adapt the commit message accordingly.

No problem I can fix them up once applying.

Thanks! If a new revision should be needed, of course I'll fix that, too.

Quoted 10 lines
Quoted 4 lines

Many thanks to those who created sashiko.dev!

Best regards
Uwe

We only received 1-3 of the 6:

https://patchwork.kernel.org/project/bluetooth/list/?series=1082520

Or is this on purpose, and we should consider the set complete?

The remaining patches are for wifi. My expectation was that they go in via wifi+netdev once the first patch is in their base. But of course I'm open for maintainer coordination to let the series go in in less steps than I expected. If that helps I can also create an immutable branch, but I have no urge here, so if only the first patch goes in during the next merge window, I won't have problems to keep track of the remaining bits.

Best regards
Uwe

#7 lore raw

Re: [PATCH v1 1/6] sdio: Add syntactic sugar to store a pointer in sdio_driver_id

Quoted 7 lines · Uwe Kleine-König (The Capable Hub)
Quoted 6 lines

We only received 1-3 of the 6:

https://patchwork.kernel.org/project/bluetooth/list/?series=1082520

Or is this on purpose, and we should consider the set complete?

Quoted 7 lines

The remaining patches are for wifi. My expectation was that they go in via wifi+netdev once the first patch is in their base. But of course I'm open for maintainer coordination to let the series go in in less steps than I expected. If that helps I can also create an immutable branch, but I have no urge here, so if only the first patch goes in during the next merge window, I won't have problems to keep track of the remaining bits.

It's probably better for everything all around, including the various automations that test patch series, if you just flip a coin, send these to either BT or WiFi, and then resend the others later :)

All assuming we get an ACK from whoever is responsible for patch 1 to merge it through some other tree :)

johannes

#8 lore raw

Re: [PATCH v1 1/6] sdio: Add syntactic sugar to store a pointer in sdio_driver_id

Hello Johannes,

Quoted 17 lines · Johannes Berg
Quoted 7 lines · Uwe Kleine-König (The Capable Hub)
Quoted 6 lines

We only received 1-3 of the 6:

https://patchwork.kernel.org/project/bluetooth/list/?series=1082520

Or is this on purpose, and we should consider the set complete?

Quoted 7 lines

The remaining patches are for wifi. My expectation was that they go in via wifi+netdev once the first patch is in their base. But of course I'm open for maintainer coordination to let the series go in in less steps than I expected. If that helps I can also create an immutable branch, but I have no urge here, so if only the first patch goes in during the next merge window, I won't have problems to keep track of the remaining bits.

Quoted 3 lines

It's probably better for everything all around, including the various automations that test patch series, if you just flip a coin, send these to either BT or WiFi, and then resend the others later :)

The first patch of this series adapting sdio_device_id is technically mmc material. However to demonstrate the upside of this patch you also have to look at at least one of bluetooth and wifi. So even if I drop one of those there are still two subsystems involved. And then in my subjective view it doesn't matter much if I involve two or three subsystems. Regarding test automations I would assume that if the bluetooth bot sees patches #1-#4 of this series it can do something already (involving either testing the series only partially or finding all 6 patches on lore). And then this isn't worse than just sending the first four patches of the series and delaying wifi until later.

But I agree that's a trade-off.

Having said that, I'm happy if the first patch is merged and patches #2 to #6 are discarded by the bluetooth and wifi people. I'll come back to them once the first patch is in a release.

Quoted 2 lines

All assuming we get an ACK from whoever is responsible for patch 1 to merge it through some other tree :)

To make this more explicit: That would be Ulf as MMC maintainer.

Best regards
Uwe

#9 lore raw

Re: [PATCH v1 1/6] sdio: Add syntactic sugar to store a pointer in sdio_driver_id

Hi Uwe,

Quoted 6 lines
Quoted 3 lines

It's probably better for everything all around, including the various automations that test patch series, if you just flip a coin, send these to either BT or WiFi, and then resend the others later :)

The first patch of this series adapting sdio_device_id is technically mmc material.

Right.

Quoted 3 lines

However to demonstrate the upside of this patch you also have to look at at least one of bluetooth and wifi. So even if I drop one of those there are still two subsystems involved.

Sure, that's fair.

Quoted 6 lines

And then in my
subjective view it doesn't matter much if I involve two or three subsystems. Regarding test automations I would assume that if the bluetooth bot sees patches #1-#4 of this series it can do something already (involving either testing the series only partially or finding all 6 patches on lore).

Yeah, that's a fair assumption, except at least for wifi, the automations (like netdev, the nipa software) only ever runs on series that it receives completely, since everyone gets CC'ed on random things too much and having the full series is a proxy for "should be applied here."

Quoted 8 lines

Having said that, I'm happy if the first patch is merged and patches #2 to #6 are discarded by the bluetooth and wifi people. I'll come back to them once the first patch is in a release.

Quoted 2 lines

All assuming we get an ACK from whoever is responsible for patch 1 to merge it through some other tree :)

To make this more explicit: That would be Ulf as MMC maintainer.

I'm also happy to merge the MMC (with Ulf's ACK) and WiFi parts, though that's even scattered with my sub-maintainers, but that just needs some coordination... I'd just like to then have a complete series on the list so I don't have to all the (build) testing manually.

If either BT or WiFi merge the relevant patches then we can sync via net-next pretty quickly and get all of it done soon, if the first patch is via MMC then it'll probably take a whole other release cycle ...

johannes

#10 lore raw

Re: [PATCH v1 1/6] sdio: Add syntactic sugar to store a pointer in sdio_driver_id

In reply to Uwe Kleine-König (The Capable Hub)
Quoted 8 lines · Uwe Kleine-König (The Capable Hub)
Quoted 7 lines · Luiz Augusto von Dentz
Quoted 5 lines · Uwe Kleine-König (The Capable Hub)
Quoted 4 lines · Uwe Kleine-König (The Capable Hub)

On all current Linux architectures sizeof(long) == sizeof(void *) and this is used a lot through the kernel. For example it enables the usual practice to store pointers in sdio_driver_id's .driver_data member.

Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

This works fine, but involves casting and thus isn't type-safe.

To be honest, with the involved void* this isn't really type-safe either, but at least the data keeps being a pointer which is really helpful on CHERI. FTR: The alternative would be to use uintptr_t instead of unsigned long, which also has proponents in the CHERI community and which is used in the current vendor patch stack.

FWIW, Linus categorically told that it has to be no uintptr_t in the Linux kernel.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw

Re: [PATCH v1 1/6] sdio: Add syntactic sugar to store a pointer in sdio_driver_id

Quoted 11 lines · Andy Shevchenko
Quoted 10 lines · Uwe Kleine-König (The Capable Hub)
Quoted 8 lines · Luiz Augusto von Dentz
Quoted 6 lines · Uwe Kleine-König (The Capable Hub)
Quoted 5 lines · Uwe Kleine-König (The Capable Hub)

On all current Linux architectures sizeof(long) == sizeof(void *) and this is used a lot through the kernel. For example it enables the usual practice to store pointers in sdio_driver_id's .driver_data member.

This works fine, but involves casting and thus isn't type-safe.

Quoted 7 lines
Quoted 5 lines

To be honest, with the involved void* this isn't really type-safe either, but at least the data keeps being a pointer which is really helpful on CHERI. FTR: The alternative would be to use uintptr_t instead of unsigned long, which also has proponents in the CHERI community and which is used in the current vendor patch stack.

FWIW, Linus categorically told that it has to be no uintptr_t in the Linux kernel.

Then I'm lucky that this patch set doesn't introduce uintptr_t and so we can delay the discussion with Linus about that. (And we will have to hold that discussion at some point, because on CHERI we have sizeof(unsigned long) = 8 < sizeof(void *) = 16. I didn't check, but I think also unsigned long long cannot hold a void*.

Best regards
Uwe

#12 lore raw

Re: [PATCH v1 1/6] sdio: Add syntactic sugar to store a pointer in sdio_driver_id

In reply to Andy Shevchenko

Hi,

Quoted 8 lines · Andy Shevchenko
Quoted 5 lines

To be honest, with the involved void* this isn't really type-safe either, but at least the data keeps being a pointer which is really helpful on CHERI. FTR: The alternative would be to use uintptr_t instead of unsigned long, which also has proponents in the CHERI community and which is used in the current vendor patch stack.

FWIW, Linus categorically told that it has to be no uintptr_t in the Linux kernel.

This is probably not the correct context to discuss this but I will point out that if/when CHERI support is added to the kernel we will need a way to distinguish between
* A (fat) pointer converted to an integer type (in order to do integer arithmetic on the address) that might be converted back to a pointer in the future and
* A plain address "extracted" from a fat pointer.
Using uintptr_t for the former and unsigned long for the latter seems like a reasonable choice but there are certainly other options.

Sorting out the difference between the two is a very large part of the diff required to port Linux (or in fact any piece of low-level software) to a CHERI system.

Best regards,
Christian

#13 lore raw

Re: [PATCH v1 1/6] sdio: Add syntactic sugar to store a pointer in sdio_driver_id

Quoted 21 lines · Christian A. Ehrhardt
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines

To be honest, with the involved void* this isn't really type-safe either, but at least the data keeps being a pointer which is really helpful on CHERI. FTR: The alternative would be to use uintptr_t instead of unsigned long, which also has proponents in the CHERI community and which is used in the current vendor patch stack.

FWIW, Linus categorically told that it has to be no uintptr_t in the Linux kernel.

This is probably not the correct context to discuss this but I will point out that if/when CHERI support is added to the kernel we will need a way to distinguish between
* A (fat) pointer converted to an integer type (in order to do integer arithmetic on the address) that might be converted back to a pointer in the future and
* A plain address "extracted" from a fat pointer.
Using uintptr_t for the former and unsigned long for the latter seems like a reasonable choice but there are certainly other options.

Quoted 3 lines

Sorting out the difference between the two is a very large part of the diff required to port Linux (or in fact any piece of low-level software) to a CHERI system.

Right, whatever CHERI needs is has to be discussed with the project leader(s) first. But thanks for giving more information on this.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#14 lore raw

Re: [PATCH v1 1/6] sdio: Add syntactic sugar to store a pointer in sdio_driver_id

In reply to Luiz Augusto von Dentz
Quoted 21 lines · Luiz Augusto von Dentz

Hi Uwe,

Quoted 17 lines · Uwe Kleine-König (The Capable Hub)

Hello,

Quoted 13 lines · Uwe Kleine-König (The Capable Hub)

On all current Linux architectures sizeof(long) == sizeof(void *) and this is used a lot through the kernel. For example it enables the usual practice to store pointers in sdio_driver_id's .driver_data member.

This works fine, but involves casting and thus isn't type-safe. Additionally with the CHERI architecture extension there are machines with sizeof(void *) > sizeof(long) for with the traditional approach of storing a pointer in .driver_data doesn't work.

By replacing the plain unsigned long .driver_data by an anonymous union, most of the casting can be dropped and it yields a working solution for CHERI.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

All users of struct sdio_driver_id are initialized in a way that is compatible with the new definition, so no adaptions are needed there.

sashiko.dev found s/sdio_driver_id/sdio_device_id/ twice in the commit log and once in the short log. If you consider applying this patch please adapt the commit message accordingly.

No problem I can fix them up once applying.

Now that Ulf gave his blessing, would you please merge the first patch and the bluetooth ones (#2 and #3)? I will follow up then once your tree hits Linus's tree with the remaining patches for wifi.

Please don't forget about s/sdio_driver_id/sdio_device_id/.

Thanks
Uwe

Acked-by on v1 1/6
#15 lore raw

Re: [PATCH v1 1/6] sdio: Add syntactic sugar to store a pointer in sdio_driver_id

In reply to Uwe Kleine-König (The Capable Hub)
Quoted 10 lines · Uwe Kleine-König (The Capable Hub)

On all current Linux architectures sizeof(long) == sizeof(void *) and this is used a lot through the kernel. For example it enables the usual practice to store pointers in sdio_driver_id's .driver_data member.

This works fine, but involves casting and thus isn't type-safe. Additionally with the CHERI architecture extension there are machines with sizeof(void *) > sizeof(long) for with the traditional approach of storing a pointer in .driver_data doesn't work.

Quoted 8 lines

By replacing the plain unsigned long .driver_data by an anonymous union, most of the casting can be dropped and it yields a working solution for CHERI.

All users of struct sdio_driver_id are initialized in a way that is compatible with the new definition, so no adaptions are needed there.

Feel free to take this via whatever tree makes best sense!

Kind regards
Uffe

Quoted 23 lines
---
 include/linux/mod_devicetable.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/linux/mod_devicetable.h +4 -2
index 5b1725fe9707..0eb5d196f5b5 100644
@@ -414,7 +414,10 @@ struct sdio_device_id {
        __u8    class;                  /* Standard interface or SDIO_ANY_ID */
        __u16   vendor;                 /* Vendor or SDIO_ANY_ID */
        __u16   device;                 /* Device ID or SDIO_ANY_ID */
-       kernel_ulong_t driver_data;     /* Data private to the driver */
+       union {                         /* Data private to the driver */
+               kernel_ulong_t driver_data;
+               const void *driver_data_ptr;
+       };
 };
 
 /* SSB core, see drivers/ssb/ */
--

2.47.3

#16 lore raw

PATCH 2/6 Bluetooth: btmrvl_sdio: Make use of driver data pointer in sdio_device_id

In reply to Uwe Kleine-König (The Capable Hub)

Recently struct sdio_device_id gained a new member to store a pointer to driver data. Make use of that to get rid of a bunch of casts.

---
 drivers/bluetooth/btmrvl_sdio.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/bluetooth/btmrvl_sdio.c +11 -11
index 93932a0d8625..ad28bee56961 100644
@@ -301,31 +301,31 @@ static const struct btmrvl_sdio_device btmrvl_sdio_sd8997 = {
 static const struct sdio_device_id btmrvl_sdio_ids[] = {
 	/* Marvell SD8688 Bluetooth device */
 	{ SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8688_BT),
-			.driver_data = (unsigned long)&btmrvl_sdio_sd8688 },
+			.driver_data_ptr = &btmrvl_sdio_sd8688 },
 	/* Marvell SD8787 Bluetooth device */
 	{ SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8787_BT),
-			.driver_data = (unsigned long)&btmrvl_sdio_sd8787 },
+			.driver_data_ptr = &btmrvl_sdio_sd8787 },
 	/* Marvell SD8787 Bluetooth AMP device */
 	{ SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8787_BT_AMP),
-			.driver_data = (unsigned long)&btmrvl_sdio_sd8787 },
+			.driver_data_ptr = &btmrvl_sdio_sd8787 },
 	/* Marvell SD8797 Bluetooth device */
 	{ SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797_BT),
-			.driver_data = (unsigned long)&btmrvl_sdio_sd8797 },
+			.driver_data_ptr = &btmrvl_sdio_sd8797 },
 	/* Marvell SD8887 Bluetooth device */
 	{ SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8887_BT),
-			.driver_data = (unsigned long)&btmrvl_sdio_sd8887 },
+			.driver_data_ptr = &btmrvl_sdio_sd8887 },
 	/* Marvell SD8897 Bluetooth device */
 	{ SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8897_BT),
-			.driver_data = (unsigned long)&btmrvl_sdio_sd8897 },
+			.driver_data_ptr = &btmrvl_sdio_sd8897 },
 	/* Marvell SD8977 Bluetooth device */
 	{ SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8977_BT),
-			.driver_data = (unsigned long)&btmrvl_sdio_sd8977 },
+			.driver_data_ptr = &btmrvl_sdio_sd8977 },
 	/* Marvell SD8987 Bluetooth device */
 	{ SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8987_BT),
-			.driver_data = (unsigned long)&btmrvl_sdio_sd8987 },
+			.driver_data_ptr = &btmrvl_sdio_sd8987 },
 	/* Marvell SD8997 Bluetooth device */
 	{ SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8997_BT),
-			.driver_data = (unsigned long)&btmrvl_sdio_sd8997 },
+			.driver_data_ptr = &btmrvl_sdio_sd8997 },
 
 	{ }	/* Terminating entry */
 };
@@ -1523,8 +1523,8 @@ static int btmrvl_sdio_probe(struct sdio_func *func,
 
 	card->func = func;
 
-	if (id->driver_data) {
-		struct btmrvl_sdio_device *data = (void *) id->driver_data;
+	if (id->driver_data_ptr) {
+		const struct btmrvl_sdio_device *data = id->driver_data_ptr;
 		card->helper = data->helper;
 		card->firmware = data->firmware;
 		card->reg = data->reg;
Signature · 1 line
2.47.3
#17 lore raw

PATCH 3/6 Bluetooth: btmtksdio: Make use of driver data pointer in sdio_device_id

In reply to Uwe Kleine-König (The Capable Hub)

Recently struct sdio_device_id gained a new member to store a pointer to driver data. Make use of that to get rid of a bunch of casts.

---
 drivers/bluetooth/btmtksdio.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/bluetooth/btmtksdio.c +4 -4
index e986e5af51ae..ee886dcada63 100644
@@ -64,11 +64,11 @@ static const struct btmtksdio_data mt7921_data = {
 
 static const struct sdio_device_id btmtksdio_table[] = {
 	{SDIO_DEVICE(SDIO_VENDOR_ID_MEDIATEK, SDIO_DEVICE_ID_MEDIATEK_MT7663),
-	 .driver_data = (kernel_ulong_t)&mt7663_data },
+	 .driver_data_ptr = &mt7663_data },
 	{SDIO_DEVICE(SDIO_VENDOR_ID_MEDIATEK, SDIO_DEVICE_ID_MEDIATEK_MT7668),
-	 .driver_data = (kernel_ulong_t)&mt7668_data },
+	 .driver_data_ptr = &mt7668_data },
 	{SDIO_DEVICE(SDIO_VENDOR_ID_MEDIATEK, SDIO_DEVICE_ID_MEDIATEK_MT7961),
-	 .driver_data = (kernel_ulong_t)&mt7921_data },
+	 .driver_data_ptr = &mt7921_data },
 	{ }	/* Terminating entry */
 };
 MODULE_DEVICE_TABLE(sdio, btmtksdio_table);
@@ -1352,7 +1352,7 @@ static int btmtksdio_probe(struct sdio_func *func,
 	if (!bdev)
 		return -ENOMEM;
 
-	bdev->data = (void *)id->driver_data;
+	bdev->data = id->driver_data_ptr;
 	if (!bdev->data)
 		return -ENODEV;
 
Signature · 1 line
2.47.3
#18 lore raw

PATCH 4/6 wifi: rtw88: Benefit from sdio_device_id::driver_data_ptr

In reply to Uwe Kleine-König (The Capable Hub)

Recently struct sdio_device_id gained a new member to store a pointer to driver data. Make use of that to get rid of a bunch of casts.

---
 drivers/net/wireless/realtek/rtw88/rtw8723cs.c | 2 +-
 drivers/net/wireless/realtek/rtw88/rtw8723ds.c | 4 ++--
 drivers/net/wireless/realtek/rtw88/rtw8821cs.c | 2 +-
 drivers/net/wireless/realtek/rtw88/rtw8822bs.c | 2 +-
 drivers/net/wireless/realtek/rtw88/rtw8822cs.c | 2 +-
 drivers/net/wireless/realtek/rtw88/sdio.c      | 2 +-
 6 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/wireless/realtek/rtw88/rtw8723cs.c +1 -1
index 2018c9d76dd1..dbe2ba989160 100644
@@ -12,7 +12,7 @@ static const struct sdio_device_id rtw_8723cs_id_table[] = {
 	{
 		SDIO_DEVICE(SDIO_VENDOR_ID_REALTEK,
 			    SDIO_DEVICE_ID_REALTEK_RTW8723CS),
-		.driver_data = (kernel_ulong_t)&rtw8703b_hw_spec,
+		.driver_data_ptr = &rtw8703b_hw_spec,
 	},
 	{}
 };
drivers/net/wireless/realtek/rtw88/rtw8723ds.c +2 -2
index e38c90b769a2..2d1872c97e30 100644
@@ -13,12 +13,12 @@ static const struct sdio_device_id rtw_8723ds_id_table[] =  {
 	{
 		SDIO_DEVICE(SDIO_VENDOR_ID_REALTEK,
 			    SDIO_DEVICE_ID_REALTEK_RTW8723DS_1ANT),
-		.driver_data = (kernel_ulong_t)&rtw8723d_hw_spec,
+		.driver_data_ptr = &rtw8723d_hw_spec,
 	},
 	{
 		SDIO_DEVICE(SDIO_VENDOR_ID_REALTEK,
 			    SDIO_DEVICE_ID_REALTEK_RTW8723DS_2ANT),
-		.driver_data = (kernel_ulong_t)&rtw8723d_hw_spec,
+		.driver_data_ptr = &rtw8723d_hw_spec,
 	},
 	{}
 };
drivers/net/wireless/realtek/rtw88/rtw8821cs.c +1 -1
index 58e0ef219cdc..7fb2d892e52d 100644
@@ -13,7 +13,7 @@ static const struct sdio_device_id rtw_8821cs_id_table[] =  {
 	{
 		SDIO_DEVICE(SDIO_VENDOR_ID_REALTEK,
 			    SDIO_DEVICE_ID_REALTEK_RTW8821CS),
-		.driver_data = (kernel_ulong_t)&rtw8821c_hw_spec,
+		.driver_data_ptr = &rtw8821c_hw_spec,
 	},
 	{}
 };
drivers/net/wireless/realtek/rtw88/rtw8822bs.c +1 -1
index 2de9b11540c5..08ae86e7ccbc 100644
@@ -13,7 +13,7 @@ static const struct sdio_device_id rtw_8822bs_id_table[] =  {
 	{
 		SDIO_DEVICE(SDIO_VENDOR_ID_REALTEK,
 			    SDIO_DEVICE_ID_REALTEK_RTW8822BS),
-		.driver_data = (kernel_ulong_t)&rtw8822b_hw_spec,
+		.driver_data_ptr = &rtw8822b_hw_spec,
 	},
 	{}
 };
drivers/net/wireless/realtek/rtw88/rtw8822cs.c +1 -1
index b00ef4173962..9a6124ea2afc 100644
@@ -13,7 +13,7 @@ static const struct sdio_device_id rtw_8822cs_id_table[] =  {
 	{
 		SDIO_DEVICE(SDIO_VENDOR_ID_REALTEK,
 			    SDIO_DEVICE_ID_REALTEK_RTW8822CS),
-		.driver_data = (kernel_ulong_t)&rtw8822c_hw_spec,
+		.driver_data_ptr = &rtw8822c_hw_spec,
 	},
 	{}
 };
drivers/net/wireless/realtek/rtw88/sdio.c +1 -1
index 1318e94f8524..f444a8f5902d 100644
@@ -1334,7 +1334,7 @@ int rtw_sdio_probe(struct sdio_func *sdio_func,
 	rtwdev = hw->priv;
 	rtwdev->hw = hw;
 	rtwdev->dev = &sdio_func->dev;
-	rtwdev->chip = (struct rtw_chip_info *)id->driver_data;
+	rtwdev->chip = id->driver_data_ptr;
 	rtwdev->hci.ops = &rtw_sdio_ops;
 	rtwdev->hci.type = RTW_HCI_TYPE_SDIO;
 
Signature · 1 line
2.47.3
#20 lore raw

PATCH 5/6 wifi: mt76: mt7921-sdio: Make use of driver data pointer in sdio_device_id

In reply to Uwe Kleine-König (The Capable Hub)

Recently struct sdio_device_id gained a new member to store a pointer to driver data. Make use of that to get rid of a bunch of casts.

The pointer is declared as const, which requires the addition of another const for mt792x_get_mac80211_ops() to make the compiler happy which is a nice side effect.

---
 drivers/net/wireless/mediatek/mt76/mt7921/sdio.c | 4 ++--
 drivers/net/wireless/mediatek/mt76/mt792x.h      | 2 +-
 drivers/net/wireless/mediatek/mt76/mt792x_core.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7921/sdio.c +2 -2
index 3421e53dc948..284529fe6282 100644
@@ -18,7 +18,7 @@
 
 static const struct sdio_device_id mt7921s_table[] = {
 	{ SDIO_DEVICE(SDIO_VENDOR_ID_MEDIATEK, 0x7901),
-		.driver_data = (kernel_ulong_t)MT7921_FIRMWARE_WM },
+		.driver_data_ptr = MT7921_FIRMWARE_WM },
 	{ }	/* Terminating entry */
 };
 
@@ -129,7 +129,7 @@ static int mt7921s_probe(struct sdio_func *func,
 	int ret;
 
 	ops = mt792x_get_mac80211_ops(&func->dev, &mt7921_ops,
-				      (void *)id->driver_data, &features);
+				      id->driver_data_ptr, &features);
 	if (!ops)
 		return -ENOMEM;
 
drivers/net/wireless/mediatek/mt76/mt792x.h +1 -1
index 8388638ed550..51c36ef4084e 100644
@@ -436,7 +436,7 @@ int mt792x_init_wiphy(struct ieee80211_hw *hw);
 struct ieee80211_ops *
 mt792x_get_mac80211_ops(struct device *dev,
 			const struct ieee80211_ops *mac80211_ops,
-			void *drv_data, u8 *fw_features);
+			const void *drv_data, u8 *fw_features);
 int mt792x_init_wcid(struct mt792x_dev *dev);
 int mt792x_mcu_drv_pmctrl(struct mt792x_dev *dev);
 int mt792x_mcu_fw_pmctrl(struct mt792x_dev *dev);
drivers/net/wireless/mediatek/mt76/mt792x_core.c +1 -1
index f2ed16feb6c1..b92bae3f2151 100644
@@ -763,7 +763,7 @@ mt792x_get_offload_capability(struct device *dev, const char *fw_wm)
 struct ieee80211_ops *
 mt792x_get_mac80211_ops(struct device *dev,
 			const struct ieee80211_ops *mac80211_ops,
-			void *drv_data, u8 *fw_features)
+			const void *drv_data, u8 *fw_features)
 {
 	struct ieee80211_ops *ops;
 
Signature · 1 line
2.47.3
#21 lore raw

PATCH 6/6 wifi: mwifiex: Make use of driver data pointer in sdio_device_id

In reply to Uwe Kleine-König (The Capable Hub)

Recently struct sdio_device_id gained a new member to store a pointer to driver data. Make use of that to get rid of a bunch of casts.

---
 drivers/net/wireless/marvell/mwifiex/sdio.c | 24 ++++++++++-----------
 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/net/wireless/marvell/mwifiex/sdio.c +12 -12
index f039d6f19183..ea227f7685b8 100644
@@ -566,8 +566,8 @@ mwifiex_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id)
 
 	func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
 
-	if (id->driver_data) {
-		struct mwifiex_sdio_device *data = (void *)id->driver_data;
+	if (id->driver_data_ptr) {
+		const struct mwifiex_sdio_device *data = id->driver_data_ptr;
 
 		card->firmware = data->firmware;
 		card->firmware_sdiouart = data->firmware_sdiouart;
@@ -955,25 +955,25 @@ static void mwifiex_sdio_coredump(struct device *dev)
 /* WLAN IDs */
 static const struct sdio_device_id mwifiex_ids[] = {
 	{SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8786_WLAN),
-		.driver_data = (unsigned long) &mwifiex_sdio_sd8786},
+		.driver_data_ptr = &mwifiex_sdio_sd8786},
 	{SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8787_WLAN),
-		.driver_data = (unsigned long) &mwifiex_sdio_sd8787},
+		.driver_data_ptr = &mwifiex_sdio_sd8787},
 	{SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797_WLAN),
-		.driver_data = (unsigned long) &mwifiex_sdio_sd8797},
+		.driver_data_ptr = &mwifiex_sdio_sd8797},
 	{SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8897_WLAN),
-		.driver_data = (unsigned long) &mwifiex_sdio_sd8897},
+		.driver_data_ptr = &mwifiex_sdio_sd8897},
 	{SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8887_WLAN),
-		.driver_data = (unsigned long)&mwifiex_sdio_sd8887},
+		.driver_data_ptr = &mwifiex_sdio_sd8887},
 	{SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8801_WLAN),
-		.driver_data = (unsigned long)&mwifiex_sdio_sd8801},
+		.driver_data_ptr = &mwifiex_sdio_sd8801},
 	{SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8977_WLAN),
-		.driver_data = (unsigned long)&mwifiex_sdio_sd8977},
+		.driver_data_ptr = &mwifiex_sdio_sd8977},
 	{SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8978_WLAN),
-		.driver_data = (unsigned long)&mwifiex_sdio_sd8978},
+		.driver_data_ptr = &mwifiex_sdio_sd8978},
 	{SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8987_WLAN),
-		.driver_data = (unsigned long)&mwifiex_sdio_sd8987},
+		.driver_data_ptr = &mwifiex_sdio_sd8987},
 	{SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8997_WLAN),
-		.driver_data = (unsigned long)&mwifiex_sdio_sd8997},
+		.driver_data_ptr = &mwifiex_sdio_sd8997},
 	{},
 };
 
Signature · 1 line
2.47.3
maintainer Acked-by on v1 6/6
#22 lore raw

Re: [PATCH v1 6/6] wifi: mwifiex: Make use of driver data pointer in sdio_device_id

Quoted 7 lines · Uwe Kleine-König (The Capable Hub)

Recently struct sdio_device_id gained a new member to store a pointer to driver data. Make use of that to get rid of a bunch of casts.

---
 drivers/net/wireless/marvell/mwifiex/sdio.c | 24 ++++++++++-----------
 1 file changed, 12 insertions(+), 12 deletions(-)