• Lukas Wunner's avatar
    spi: gpio: Don't leak SPI master in probe error path · 7174dc65
    Lukas Wunner authored
    If the call to devm_spi_register_master() fails on probe of the GPIO SPI
    driver, the spi_master struct is erroneously not freed:
    
    After allocating the spi_master, its reference count is 1.  The driver
    unconditionally decrements the reference count on unbind using a devm
    action.  Before calling devm_spi_register_master(), the driver
    unconditionally increments the reference count because on success,
    that function will decrement the reference count on unbind.  However on
    failure, devm_spi_register_master() does *not* decrement the reference
    count, so the spi_master is leaked.
    
    The issue was introduced by commits 8b797490 ("spi: gpio: Make sure
    spi_master_put() is called in every error path") and 79567c1a ("spi:
    gpio: Use devm_spi_register_master()"), which sought to plug leaks
    introduced by 9b00bc7b ("spi: spi-gpio: Rewrite to use GPIO
    descriptors") but missed this remaining leak.
    
    The situation was later aggravated by commit d3b0ffa1 ("spi...
    7174dc65
spi-gpio.c 12.8 KB