Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: typec: tipd: Add cd321x struct with separate size

We're about to add more fields to struct tps6598x which are only relevant
for Apple's CD321x and to ensure that we don't waste memory everywhere for
those add a separate struct for cd321x and prepare to allocate more space
inside probe.

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Neal Gompa <neal@gompa.dev>
Signed-off-by: Sven Peter <sven@kernel.org>
Link: https://lore.kernel.org/r/20250914-apple-usb3-tipd-v1-5-4e99c8649024@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Sven Peter and committed by
Greg Kroah-Hartman
9f36fdfc 60e1ff66

+15 -5
+15 -5
drivers/usb/typec/tipd/core.c
··· 113 113 struct tipd_data { 114 114 irq_handler_t irq_handler; 115 115 u64 irq_mask1; 116 + size_t tps_struct_size; 116 117 int (*register_port)(struct tps6598x *tps, struct fwnode_handle *node); 117 118 void (*trace_data_status)(u32 status); 118 119 void (*trace_power_status)(u16 status); ··· 147 146 struct delayed_work wq_poll; 148 147 149 148 const struct tipd_data *data; 149 + }; 150 + 151 + struct cd321x { 152 + struct tps6598x tps; 150 153 }; 151 154 152 155 static enum power_supply_property tps6598x_psy_props[] = { ··· 1302 1297 1303 1298 static int tps6598x_probe(struct i2c_client *client) 1304 1299 { 1300 + const struct tipd_data *data; 1305 1301 struct tps6598x *tps; 1306 1302 struct fwnode_handle *fwnode; 1307 1303 u32 status; 1308 1304 u32 vid; 1309 1305 int ret; 1310 1306 1311 - tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); 1307 + data = i2c_get_match_data(client); 1308 + if (!data) 1309 + return -EINVAL; 1310 + 1311 + tps = devm_kzalloc(&client->dev, data->tps_struct_size, GFP_KERNEL); 1312 1312 if (!tps) 1313 1313 return -ENOMEM; 1314 1314 1315 1315 mutex_init(&tps->lock); 1316 1316 tps->dev = &client->dev; 1317 + tps->data = data; 1317 1318 1318 1319 tps->reset = devm_gpiod_get_optional(tps->dev, "reset", GPIOD_OUT_LOW); 1319 1320 if (IS_ERR(tps->reset)) ··· 1344 1333 */ 1345 1334 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 1346 1335 tps->i2c_protocol = true; 1347 - 1348 - tps->data = i2c_get_match_data(client); 1349 - if (!tps->data) 1350 - return -EINVAL; 1351 1336 1352 1337 if (tps->data->switch_power_state) { 1353 1338 ret = tps->data->switch_power_state(tps, TPS_SYSTEM_POWER_STATE_S0); ··· 1528 1521 .irq_mask1 = APPLE_CD_REG_INT_POWER_STATUS_UPDATE | 1529 1522 APPLE_CD_REG_INT_DATA_STATUS_UPDATE | 1530 1523 APPLE_CD_REG_INT_PLUG_EVENT, 1524 + .tps_struct_size = sizeof(struct cd321x), 1531 1525 .register_port = tps6598x_register_port, 1532 1526 .trace_data_status = trace_cd321x_data_status, 1533 1527 .trace_power_status = trace_tps6598x_power_status, ··· 1543 1535 .irq_mask1 = TPS_REG_INT_POWER_STATUS_UPDATE | 1544 1536 TPS_REG_INT_DATA_STATUS_UPDATE | 1545 1537 TPS_REG_INT_PLUG_EVENT, 1538 + .tps_struct_size = sizeof(struct tps6598x), 1546 1539 .register_port = tps6598x_register_port, 1547 1540 .trace_data_status = trace_tps6598x_data_status, 1548 1541 .trace_power_status = trace_tps6598x_power_status, ··· 1558 1549 .irq_mask1 = TPS_REG_INT_POWER_STATUS_UPDATE | 1559 1550 TPS_REG_INT_DATA_STATUS_UPDATE | 1560 1551 TPS_REG_INT_PLUG_EVENT, 1552 + .tps_struct_size = sizeof(struct tps6598x), 1561 1553 .register_port = tps25750_register_port, 1562 1554 .trace_data_status = trace_tps6598x_data_status, 1563 1555 .trace_power_status = trace_tps25750_power_status,