# Re: \[PATCH V2 2/2\] Input: spear-keyboard: add device tree bindings

- From: Dmitry Torokhov \<dmitry.torokhov@gmail.com\>
- Date: 2012-03-27 07:13:35 
- List: linux-input
- Page: https://ratatoskr.run/linux-input/2012/03/8058850
- Thread: https://ratatoskr.run/linux-input/2012/03/8058848/t.md

```text
Hi Viresh,

On Tue, Mar 27, 2012 at 11:08:12AM +0530, Viresh Kumar wrote:
> +	if (np) {
> +		pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
> +		if (!pdata) {
> +			dev_err(&pdev->dev, "DT: kzalloc failed\n");
> +			return -ENOMEM;
> +		}
> +
> +		pdev->dev.platform_data = pdata;
> +		error = spear_kbd_probe_dt(pdev);
> +		if (error) {
> +			dev_err(&pdev->dev, "DT: no platform data\n");
> +			return error;
> +		}
> +	} else {
> +		pdata = dev_get_platdata(&pdev->dev);
> +		if (!pdata || !pdata->keymap) {
> +			dev_err(&pdev->dev, "Invalid platform data\n");
> +			return -EINVAL;
> +		}
>  	}

I think the opposite order woudl make more sense - if pdata is supplied
by the platform code then we should use it, otherwise try to see if
there is OF data available instead. This way one can easily override OF
data, if needed.

Same goes for keymap data.

Thanks.

-- 
Dmitry
```
