Skip to content

Commit 0cbf08d

Browse files
committed
[DNM] drivers: stm32: use device_get/put
Use device_get/put. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
1 parent f24721d commit 0cbf08d

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

drivers/gpio/gpio_stm32.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,9 @@ static int gpio_stm32_init(const struct device *dev)
714714

715715
data->dev = dev;
716716

717-
if (!device_is_ready(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE))) {
718-
return -ENODEV;
717+
ret = device_get(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE));
718+
if (ret < 0) {
719+
return ret;
719720
}
720721

721722
#if (defined(PWR_CR2_IOSV) || defined(PWR_SVMCR_IO2SV)) && \

drivers/pinctrl/pinctrl_stm32.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,24 @@ static int stm32_pins_remap(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt)
211211
static int stm32_pin_configure(uint32_t pin, uint32_t pin_cgf, uint32_t pin_func)
212212
{
213213
const struct device *port_device;
214+
int ret;
214215

215216
if (STM32_PORT(pin) >= gpio_ports_cnt) {
216217
return -EINVAL;
217218
}
218219

219220
port_device = gpio_ports[STM32_PORT(pin)];
220221

221-
if ((port_device == NULL) || (!device_is_ready(port_device))) {
222-
return -ENODEV;
222+
ret = device_get(port_device);
223+
if (ret < 0) {
224+
return ret;
223225
}
224226

225-
return gpio_stm32_configure(port_device, STM32_PIN(pin), pin_cgf, pin_func);
227+
ret = gpio_stm32_configure(port_device, STM32_PIN(pin), pin_cgf, pin_func);
228+
229+
(void)device_put(port_device);
230+
231+
return ret;
226232
}
227233

228234
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt,

drivers/serial/uart_stm32.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,18 +1815,21 @@ static int uart_stm32_async_init(const struct device *dev)
18151815
const struct uart_stm32_config *config = dev->config;
18161816
USART_TypeDef *usart = config->usart;
18171817
struct uart_stm32_data *data = dev->data;
1818+
int ret;
18181819

18191820
data->uart_dev = dev;
18201821

18211822
if (data->dma_rx.dma_dev != NULL) {
1822-
if (!device_is_ready(data->dma_rx.dma_dev)) {
1823-
return -ENODEV;
1823+
ret = device_get(data->dma_rx.dma_dev);
1824+
if (ret < 0) {
1825+
return ret;
18241826
}
18251827
}
18261828

18271829
if (data->dma_tx.dma_dev != NULL) {
1828-
if (!device_is_ready(data->dma_tx.dma_dev)) {
1829-
return -ENODEV;
1830+
ret = device_get(data->dma_tx.dma_dev);
1831+
if (ret < 0) {
1832+
return ret;
18301833
}
18311834
}
18321835

@@ -1998,9 +2001,10 @@ static int uart_stm32_clocks_enable(const struct device *dev)
19982001

19992002
__uart_stm32_get_clock(dev);
20002003

2001-
if (!device_is_ready(data->clock)) {
2004+
err = device_get(data->clock);
2005+
if (err < 0) {
20022006
LOG_ERR("clock control device not ready");
2003-
return -ENODEV;
2007+
return err;
20042008
}
20052009

20062010
/* enable clock */
@@ -2029,12 +2033,14 @@ static int uart_stm32_registers_configure(const struct device *dev)
20292033
USART_TypeDef *usart = config->usart;
20302034
struct uart_stm32_data *data = dev->data;
20312035
struct uart_config *uart_cfg = data->uart_cfg;
2036+
int ret;
20322037

20332038
LL_USART_Disable(usart);
20342039

2035-
if (!device_is_ready(config->reset.dev)) {
2040+
ret = device_get(config->reset.dev);
2041+
if (ret < 0) {
20362042
LOG_ERR("reset controller not ready");
2037-
return -ENODEV;
2043+
return ret;
20382044
}
20392045

20402046
/* Reset UART to default state using RCC */

0 commit comments

Comments
 (0)