Skip to content

Commit

Permalink
spi: Fix reference count leak in slave_show()
Browse files Browse the repository at this point in the history
Fix a reference count leak in slave_show() by properly putting the device
reference obtained from device_find_any_child().

Fixes: 6c36406 ("spi: core: Add support for registering SPI slave controllers")
Fixes: c21b083 ("spi: Use device_find_any_child() instead of custom approach")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://patch.msgid.link/20250319032305.70340-1-linmq006@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Miaoqian Lin authored and Mark Brown committed Mar 19, 2025
1 parent 4701f33 commit 176fda5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/spi/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2954,9 +2954,13 @@ static ssize_t slave_show(struct device *dev, struct device_attribute *attr,
struct spi_controller *ctlr = container_of(dev, struct spi_controller,
dev);
struct device *child;
int ret;

child = device_find_any_child(&ctlr->dev);
return sysfs_emit(buf, "%s\n", child ? to_spi_device(child)->modalias : NULL);
ret = sysfs_emit(buf, "%s\n", child ? to_spi_device(child)->modalias : NULL);
put_device(child);

return ret;
}

static ssize_t slave_store(struct device *dev, struct device_attribute *attr,
Expand Down

0 comments on commit 176fda5

Please sign in to comment.