Re: [PATCH] base/platform: fix panic when probe function is NULL

From: Wilck, Martin
Date: Tue Dec 01 2015 - 05:42:00 EST


Hello Uwe,

> This sounds like a separate issue though. Looking at init_tis there is:
>
> rc = platform_driver_register(&tis_drv);
> if (rc < 0)
> return rc;
> pdev = platform_device_register_simple("tpm_tis", -1, NULL, 0);
> if (IS_ERR(pdev)) {
> rc = PTR_ERR(pdev);
> goto err_dev;
> }
> rc = tpm_tis_init(&pdev->dev, &tis_default_info, NULL);
>
> tpm_tis_init calls tpmm_chip_alloc which barfs when pdev (i.e. the return value
> of platform_device_register_simple above) isn't bound. It is not allowed
> to assume that the device is bound after the above function calls.

Can you please explain again why you think that assumption is invalid?
As far as I understand the code, the assumption would be correct in
4.3.0 and earlier:

platform_driver_register() registers a platform driver with name
"tpm_tis". platform_device_register_simple() registers a device with the
same name. This will call platform_device_add()/device_add() and start
probing for a platform device. Platform bus probing in platform_match()
falls back to a simple match between driver and device name if all else
fails. That match succeeds for the "tpm_tis" driver. Thus
driver_probe_device() will be called, and in the absence of a
driver-specific probe routine, will succeed. Thus after
platform_device_register_simple() returns, device and driver will be
bound. This matches also actual behavior of the pre-4.4 code.

Please explain what I am overlooking. I am just trying to understand.
As far as tpm_tis is concerned, Jason's current patch set is going to
fix this for good anyway.

Regards
Martin