mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	bus: ts-nbus: Improve error reporting
Using dev_err_probe() brings several improvements: - emits the symbolic error code - properly handles EPROBE_DEFER - combines error message generation and return value handling While at it add error messages to two error paths that were silent before. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
This commit is contained in:
		
							parent
							
								
									8129d25e32
								
							
						
					
					
						commit
						a04a7da398
					
				
					 1 changed files with 28 additions and 38 deletions
				
			
		| 
						 | 
					@ -39,45 +39,39 @@ struct ts_nbus {
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * request all gpios required by the bus.
 | 
					 * request all gpios required by the bus.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static int ts_nbus_init_pdata(struct platform_device *pdev, struct ts_nbus
 | 
					static int ts_nbus_init_pdata(struct platform_device *pdev,
 | 
				
			||||||
		*ts_nbus)
 | 
								      struct ts_nbus *ts_nbus)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	ts_nbus->data = devm_gpiod_get_array(&pdev->dev, "ts,data",
 | 
						ts_nbus->data = devm_gpiod_get_array(&pdev->dev, "ts,data",
 | 
				
			||||||
			GPIOD_OUT_HIGH);
 | 
								GPIOD_OUT_HIGH);
 | 
				
			||||||
	if (IS_ERR(ts_nbus->data)) {
 | 
						if (IS_ERR(ts_nbus->data))
 | 
				
			||||||
		dev_err(&pdev->dev, "failed to retrieve ts,data-gpio from dts\n");
 | 
							return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->data),
 | 
				
			||||||
		return PTR_ERR(ts_nbus->data);
 | 
									     "failed to retrieve ts,data-gpio from dts\n");
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ts_nbus->csn = devm_gpiod_get(&pdev->dev, "ts,csn", GPIOD_OUT_HIGH);
 | 
						ts_nbus->csn = devm_gpiod_get(&pdev->dev, "ts,csn", GPIOD_OUT_HIGH);
 | 
				
			||||||
	if (IS_ERR(ts_nbus->csn)) {
 | 
						if (IS_ERR(ts_nbus->csn))
 | 
				
			||||||
		dev_err(&pdev->dev, "failed to retrieve ts,csn-gpio from dts\n");
 | 
							return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->csn),
 | 
				
			||||||
		return PTR_ERR(ts_nbus->csn);
 | 
								      "failed to retrieve ts,csn-gpio from dts\n");
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ts_nbus->txrx = devm_gpiod_get(&pdev->dev, "ts,txrx", GPIOD_OUT_HIGH);
 | 
						ts_nbus->txrx = devm_gpiod_get(&pdev->dev, "ts,txrx", GPIOD_OUT_HIGH);
 | 
				
			||||||
	if (IS_ERR(ts_nbus->txrx)) {
 | 
						if (IS_ERR(ts_nbus->txrx))
 | 
				
			||||||
		dev_err(&pdev->dev, "failed to retrieve ts,txrx-gpio from dts\n");
 | 
							return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->txrx),
 | 
				
			||||||
		return PTR_ERR(ts_nbus->txrx);
 | 
									     "failed to retrieve ts,txrx-gpio from dts\n");
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ts_nbus->strobe = devm_gpiod_get(&pdev->dev, "ts,strobe", GPIOD_OUT_HIGH);
 | 
						ts_nbus->strobe = devm_gpiod_get(&pdev->dev, "ts,strobe", GPIOD_OUT_HIGH);
 | 
				
			||||||
	if (IS_ERR(ts_nbus->strobe)) {
 | 
						if (IS_ERR(ts_nbus->strobe))
 | 
				
			||||||
		dev_err(&pdev->dev, "failed to retrieve ts,strobe-gpio from dts\n");
 | 
							return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->strobe),
 | 
				
			||||||
		return PTR_ERR(ts_nbus->strobe);
 | 
									     "failed to retrieve ts,strobe-gpio from dts\n");
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ts_nbus->ale = devm_gpiod_get(&pdev->dev, "ts,ale", GPIOD_OUT_HIGH);
 | 
						ts_nbus->ale = devm_gpiod_get(&pdev->dev, "ts,ale", GPIOD_OUT_HIGH);
 | 
				
			||||||
	if (IS_ERR(ts_nbus->ale)) {
 | 
						if (IS_ERR(ts_nbus->ale))
 | 
				
			||||||
		dev_err(&pdev->dev, "failed to retrieve ts,ale-gpio from dts\n");
 | 
							return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->ale),
 | 
				
			||||||
		return PTR_ERR(ts_nbus->ale);
 | 
									     "failed to retrieve ts,ale-gpio from dts\n");
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ts_nbus->rdy = devm_gpiod_get(&pdev->dev, "ts,rdy", GPIOD_IN);
 | 
						ts_nbus->rdy = devm_gpiod_get(&pdev->dev, "ts,rdy", GPIOD_IN);
 | 
				
			||||||
	if (IS_ERR(ts_nbus->rdy)) {
 | 
						if (IS_ERR(ts_nbus->rdy))
 | 
				
			||||||
		dev_err(&pdev->dev, "failed to retrieve ts,rdy-gpio from dts\n");
 | 
							return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->rdy),
 | 
				
			||||||
		return PTR_ERR(ts_nbus->rdy);
 | 
									     "failed to retrieve ts,rdy-gpio from dts\n");
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -289,25 +283,20 @@ static int ts_nbus_probe(struct platform_device *pdev)
 | 
				
			||||||
		return ret;
 | 
							return ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pwm = devm_pwm_get(dev, NULL);
 | 
						pwm = devm_pwm_get(dev, NULL);
 | 
				
			||||||
	if (IS_ERR(pwm)) {
 | 
						if (IS_ERR(pwm))
 | 
				
			||||||
		ret = PTR_ERR(pwm);
 | 
							return dev_err_probe(dev, PTR_ERR(pwm),
 | 
				
			||||||
		if (ret != -EPROBE_DEFER)
 | 
									     "unable to request PWM\n");
 | 
				
			||||||
			dev_err(dev, "unable to request PWM\n");
 | 
					 | 
				
			||||||
		return ret;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pwm_init_state(pwm, &state);
 | 
						pwm_init_state(pwm, &state);
 | 
				
			||||||
	if (!state.period) {
 | 
						if (!state.period)
 | 
				
			||||||
		dev_err(&pdev->dev, "invalid PWM period\n");
 | 
							return dev_err_probe(dev, -EINVAL, "invalid PWM period\n");
 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	state.duty_cycle = state.period;
 | 
						state.duty_cycle = state.period;
 | 
				
			||||||
	state.enabled = true;
 | 
						state.enabled = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = pwm_apply_state(pwm, &state);
 | 
						ret = pwm_apply_state(pwm, &state);
 | 
				
			||||||
	if (ret < 0)
 | 
						if (ret < 0)
 | 
				
			||||||
		return ret;
 | 
							return dev_err_probe(dev, ret, "failed to configure PWM\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * we can now start the FPGA and populate the peripherals.
 | 
						 * we can now start the FPGA and populate the peripherals.
 | 
				
			||||||
| 
						 | 
					@ -321,7 +310,8 @@ static int ts_nbus_probe(struct platform_device *pdev)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
 | 
						ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
 | 
				
			||||||
	if (ret < 0)
 | 
						if (ret < 0)
 | 
				
			||||||
		return ret;
 | 
							return dev_err_probe(dev, ret,
 | 
				
			||||||
 | 
									     "failed to populate platform devices on bus\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dev_info(dev, "initialized\n");
 | 
						dev_info(dev, "initialized\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue