Skip to content

platform/chrome: Fix a race when probing drivers

Tzung-Bi Shih chrome-platform linux-input 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 9 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5platform/chrome: Centralize cros_ec_device allocationdrivers/platform/chrome/cros_ec.c drivers/platform/chrome/cros_ec.h drivers/platform/chrome/cros_ec_i2c.c +5 more+22 -70 replies
2/5platform/chrome: Centralize common cros_ec_device initializationdrivers/platform/chrome/cros_ec.c drivers/platform/chrome/cros_ec_i2c.c drivers/platform/chrome/cros_ec_ishtp.c +5 more+19 -300 replies
3/5platform/chrome: cros_ec: Separate initialization from cros_ec_register()drivers/platform/chrome/cros_ec.c+30 -270 replies
4/5platform/chrome: cros_ec: Add a flag to track registration statedrivers/platform/chrome/cros_ec.c drivers/platform/chrome/cros_ec_proto.c include/linux/platform_data/cros_ec_proto.h+26 -00 replies
5/5Input: cros_ec_keyb - Defer probe until parent EC device is registereddrivers/input/keyboard/cros_ec_keyb.c+6 -01 reply

Reviews trailers per patch

1 of 5 patches has a Reviewed-by or Acked-by.

PatchDmitry Torokhov
1/5
2/5
3/5
4/5
5/5A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/5] platform/chrome: Fix a race when probing drivers

A race is observed when cros_ec_lpc and cros-ec-keyb are all built as modules. cros_ec_lpc is cros-ec-keyb's parent. However, they can be probed at the same time.

Example:

+ -----------------------------------------------------------------+ | Some init process (e.g. udevd) | deferred_probe_work_func worker |
+ -----------------------------------------------------------------+

| Probe cros-ec-keyb.            |                                 |
| - Decide to defer[1].          |                                 |
|                                | A device bound to a driver[2].  |
| Probe cros_ec_lpc.             |                                 |
| - Init the struct[3].          |                                 |
|                                | Retry cros-ec-keyb from the     |
|                                | deferred list[4].               |
|                                | - Won't defer again as [3].     |
|                                | - Access uninitialized data in  |
|                                |   the struct.                   |
| - Register the device.         |                                 |

+ -----------------------------------------------------------------+

[1] https://elixir.bootlin.com/linux/v6.16/source/drivers/input/keyboard/cros_ec_keyb.c#L707
[2] https://elixir.bootlin.com/linux/v6.16/source/drivers/base/dd.c#L405
[3] https://elixir.bootlin.com/linux/v6.16/source/drivers/platform/chrome/cros_ec_lpc.c#L644
[4] https://elixir.bootlin.com/linux/v6.16/source/drivers/base/dd.c#L418

Note that the device link[5] can't help as in the observed environment, the devices are already added via device_add()[6].

[5] https://www.kernel.org/doc/html/latest/driver-api/device_link.html#usage
[6] https://elixir.bootlin.com/linux/v6.16/source/drivers/acpi/acpi_platform.c#L177

The series fixes the issue by ensuring the struct is ready for accessing before continuing to probe cros-ec-keyb.

The 1st - 3rd patches are preparatory steps to allow the per-device lock can be used even if the struct cros_ec_device is unregistered.

The 4th patch introduces a new flag registered and use the lock for protecting the flag.

The 5th patch defers probe if the struct cros_ec_device is not ready yet.

Tzung-Bi Shih (5):
platform/chrome: Centralize cros_ec_device allocation platform/chrome: Centralize common cros_ec_device initialization platform/chrome: cros_ec: Separate initialization from
cros_ec_register()
platform/chrome: cros_ec: Add a flag to track registration state
Input: cros_ec_keyb - Defer probe until parent EC device is registered

 drivers/input/keyboard/cros_ec_keyb.c       |  6 ++
 drivers/platform/chrome/cros_ec.c           | 85 ++++++++++++++-------
 drivers/platform/chrome/cros_ec.h           |  3 +
 drivers/platform/chrome/cros_ec_i2c.c       |  9 +--
 drivers/platform/chrome/cros_ec_ishtp.c     |  6 +-
 drivers/platform/chrome/cros_ec_lpc.c       |  6 +-
 drivers/platform/chrome/cros_ec_proto.c     | 15 ++++
 drivers/platform/chrome/cros_ec_rpmsg.c     |  6 +-
 drivers/platform/chrome/cros_ec_spi.c       |  7 +-
 drivers/platform/chrome/cros_ec_uart.c      |  6 +-
 include/linux/platform_data/cros_ec_proto.h | 18 ++++-
 11 files changed, 103 insertions(+), 64 deletions(-)
Signature · 1 line
2.51.0.268.g9569e192d0-goog