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.

platform/chrome: cros_ec: Separate initialization from cros_ec_register()

Move the initialization of the `struct cros_ec_device` from
cros_ec_register() into cros_ec_device_alloc().

This decouples device initialization from registration. By doing so,
the per-device lock is now available immediately after allocation,
allowing it to be used safely even before the device is fully
registered.

Link: https://lore.kernel.org/r/20250828083601.856083-4-tzungbi@kernel.org
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

+30 -27
+30 -27
drivers/platform/chrome/cros_ec.c
··· 30 30 .cmd_offset = EC_CMD_PASSTHRU_OFFSET(CROS_EC_DEV_PD_INDEX), 31 31 }; 32 32 33 + static void cros_ec_device_free(void *data) 34 + { 35 + struct cros_ec_device *ec_dev = data; 36 + 37 + mutex_destroy(&ec_dev->lock); 38 + lockdep_unregister_key(&ec_dev->lockdep_key); 39 + } 40 + 33 41 struct cros_ec_device *cros_ec_device_alloc(struct device *dev) 34 42 { 35 43 struct cros_ec_device *ec_dev; ··· 53 45 sizeof(struct ec_params_rwsig_action) + 54 46 EC_MAX_REQUEST_OVERHEAD; 55 47 48 + ec_dev->din = devm_kzalloc(dev, ec_dev->din_size, GFP_KERNEL); 49 + if (!ec_dev->din) 50 + return NULL; 51 + 52 + ec_dev->dout = devm_kzalloc(dev, ec_dev->dout_size, GFP_KERNEL); 53 + if (!ec_dev->dout) 54 + return NULL; 55 + 56 56 ec_dev->dev = dev; 57 + ec_dev->max_response = sizeof(struct ec_response_get_protocol_info); 58 + ec_dev->max_request = sizeof(struct ec_params_rwsig_action); 59 + ec_dev->suspend_timeout_ms = EC_HOST_SLEEP_TIMEOUT_DEFAULT; 60 + 61 + BLOCKING_INIT_NOTIFIER_HEAD(&ec_dev->event_notifier); 62 + BLOCKING_INIT_NOTIFIER_HEAD(&ec_dev->panic_notifier); 63 + 64 + lockdep_register_key(&ec_dev->lockdep_key); 65 + mutex_init(&ec_dev->lock); 66 + lockdep_set_class(&ec_dev->lock, &ec_dev->lockdep_key); 67 + 68 + if (devm_add_action_or_reset(dev, cros_ec_device_free, ec_dev)) 69 + return NULL; 57 70 58 71 return ec_dev; 59 72 } ··· 229 200 int cros_ec_register(struct cros_ec_device *ec_dev) 230 201 { 231 202 struct device *dev = ec_dev->dev; 232 - int err = 0; 233 - 234 - BLOCKING_INIT_NOTIFIER_HEAD(&ec_dev->event_notifier); 235 - BLOCKING_INIT_NOTIFIER_HEAD(&ec_dev->panic_notifier); 236 - 237 - ec_dev->max_request = sizeof(struct ec_params_hello); 238 - ec_dev->max_response = sizeof(struct ec_response_get_protocol_info); 239 - ec_dev->max_passthru = 0; 240 - ec_dev->ec = NULL; 241 - ec_dev->pd = NULL; 242 - ec_dev->suspend_timeout_ms = EC_HOST_SLEEP_TIMEOUT_DEFAULT; 243 - 244 - ec_dev->din = devm_kzalloc(dev, ec_dev->din_size, GFP_KERNEL); 245 - if (!ec_dev->din) 246 - return -ENOMEM; 247 - 248 - ec_dev->dout = devm_kzalloc(dev, ec_dev->dout_size, GFP_KERNEL); 249 - if (!ec_dev->dout) 250 - return -ENOMEM; 251 - 252 - lockdep_register_key(&ec_dev->lockdep_key); 253 - mutex_init(&ec_dev->lock); 254 - lockdep_set_class(&ec_dev->lock, &ec_dev->lockdep_key); 203 + int err; 255 204 256 205 /* Send RWSIG continue to jump to RW for devices using RWSIG. */ 257 206 err = cros_ec_rwsig_continue(ec_dev); ··· 329 322 exit: 330 323 platform_device_unregister(ec_dev->ec); 331 324 platform_device_unregister(ec_dev->pd); 332 - mutex_destroy(&ec_dev->lock); 333 - lockdep_unregister_key(&ec_dev->lockdep_key); 334 325 return err; 335 326 } 336 327 EXPORT_SYMBOL(cros_ec_register); ··· 348 343 &ec_dev->notifier_ready); 349 344 platform_device_unregister(ec_dev->pd); 350 345 platform_device_unregister(ec_dev->ec); 351 - mutex_destroy(&ec_dev->lock); 352 - lockdep_unregister_key(&ec_dev->lockdep_key); 353 346 } 354 347 EXPORT_SYMBOL(cros_ec_unregister); 355 348