History

net: dsa: microchip: properly support platform_data probing

The ksz driver has bits and pieces of platform_data probing support, but it doesn't work. The conventional thing to do is to have an encapsulating structure for struct dsa_chip_data that gets put into dev->platform_data. This driver expects a struct ksz_platform_data, but that doesn't contain a struct dsa_chip_data as first element, which will obviously not work with dsa_switch_probe() -> dsa_switch_parse(). Pointing dev->platform_data to a struct dsa_chip_data directly is in principle possible, but that doesn't work either. The driver has ksz_switch_detect() to read the device ID from hardware, followed by ksz_check_device_id() to compare it against a predetermined expected value. This protects against early errors in the SPI/I2C communication. With platform_data, the mechanism in ksz_check_device_id() doesn't work and even leads to NULL pointer dereferences, since of_device_get_match_data() doesn't work in that probe path. So obviously, the platform_data support is actually missing, and the existing handling of struct ksz_platform_data is bogus. Complete the support by adding a struct dsa_chip_data as first element, and fixing up ksz_check_device_id() to pick up the platform_data instead of the unavailable of_device_get_match_data(). The early dev->chip_id assignment from ksz_switch_register() is also bogus, because ksz_switch_detect() sets it to an initial value. So remove it. Also, ksz_platform_data :: enabled_ports isn't used anywhere, delete it.

Vladimir Oltean committed 2 years ago

Commit 3bc05fa1 parent d5449d52 files · +16 −9Browse files

Showing the changes to include/linux/platform_data (1 of 2 files). Show all

Unified · Split

include/linux/platform_data/microchip-ksz.h+3−1
@@ -20,10 +20,12 @@ · 19 unmodified lines
20#define __MICROCHIP_KSZ_H20#define __MICROCHIP_KSZ_H
21 21
22#include <linux/types.h>22#include <linux/types.h>
23#include <linux/platform_data/dsa.h>
23 24
24struct ksz_platform_data {25struct ksz_platform_data {
26 /* Must be first such that dsa_register_switch() can access it */
27 struct dsa_chip_data cd;
25 u32 chip_id;28 u32 chip_id;
26 u16 enabled_ports;
27};29};
28 30
29#endif31#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t