Skip to content

base/platform: Platform data and resources NULL handling

Anton Vorontsov lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2base/platform: Safe handling for NULL platform data and resourcesdrivers/base/platform.c+8 -10 replies
2/2base/platform: Simplifications for NULL platform data/resources handlingdrivers/base/platform.c+12 -200 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] base/platform: Platform data and resources NULL handling

Hi all,

There is a bug in the MFD core code (drivers/mfd/mfd-core.c), the mfd_add_device function does not check platform_data for NULL, and thus always calls platform_device_add_data():

static int mfd_add_device(struct device *parent, int id, [...])

{
	[...]
	ret = platform_device_add_data(pdev,
		cell->platform_data, cell->data_size);
	[...]
}

The problem is that when cell->platform_data is NULL, the platform core calls kmemdup(NULL, 0, ...), which returns a non-NULL result (ZERO_SIZE_PTR), and the result is stored in the dev.platform_data. This causes drivers to oops on a valid code:

if (pdata)

	stuff = pdata->stuff;

Firstly I thought that I would fix the MFD core, but it appears that the better approach would be to change device_add_data() call behaviour, and thus make the core code more safe.

There are two patches: a patch that is necessary for the bug fix, and a non-essential cleanup patch.

Thanks,

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2