Skip to contentSkip to conversation

Input: Fix memory leak in psxpad_spi_probe

PATCH In review Navid Emamdoost 3 participants 4 messages Nov 21, 2019 – Dec 7, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: Fix memory leak in psxpad_spi_probe

In the implementation of psxpad_spi_probe() the allocated memory for pdev is leaked if psxpad_spi_init_ff() or input_register_polled_device() fail. The solution is using device managed allocation, like the one used for pad. Perform the allocation using devm_input_allocate_polled_device().

Fixes 8be193c7b1f4 ("Input: add support for PlayStation 1/2 joypads connected via SPI")
---
 drivers/input/joystick/psxpad-spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/joystick/psxpad-spi.c +1 -1
index 7eee1b0e360f..99a6052500ca 100644
@@ -292,7 +292,7 @@ static int psxpad_spi_probe(struct spi_device *spi)
 	if (!pad)
 		return -ENOMEM;
 
-	pdev = input_allocate_polled_device();
+	pdev = devm_input_allocate_polled_device(&spi->dev);
 	if (!pdev) {
 		dev_err(&spi->dev, "failed to allocate input device\n");
 		return -ENOMEM;
Signature · 1 line
2.17.1
maintainer Acked-by on v1 1/1
#1 lore raw

Hi Navid,

Quoted 8 lines · Navid Emamdoost

In the implementation of psxpad_spi_probe() the allocated memory for pdev is leaked if psxpad_spi_init_ff() or input_register_polled_device() fail. The solution is using device managed allocation, like the one used for pad. Perform the allocation using devm_input_allocate_polled_device().

Fixes 8be193c7b1f4 ("Input: add support for PlayStation 1/2 joypads connected via SPI")

This is fixed in the current version of the driver, but you can send it to [email protected] with my

Quoted 20 lines
---
 drivers/input/joystick/psxpad-spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/joystick/psxpad-spi.c +1 -1
index 7eee1b0e360f..99a6052500ca 100644
@@ -292,7 +292,7 @@ static int psxpad_spi_probe(struct spi_device *spi)
 	if (!pad)
 		return -ENOMEM;
 
-	pdev = input_allocate_polled_device();
+	pdev = devm_input_allocate_polled_device(&spi->dev);
 	if (!pdev) {
 		dev_err(&spi->dev, "failed to allocate input device\n");
 		return -ENOMEM;
Signature · 1 line
2.17.1
Signature · 1 line
Dmitry
#2 lore raw
Quoted 9 lines · Dmitry Torokhov

Hi Navid,

Quoted 6 lines · Navid Emamdoost

In the implementation of psxpad_spi_probe() the allocated memory for pdev is leaked if psxpad_spi_init_ff() or input_register_polled_device() fail. The solution is using device managed allocation, like the one used for pad. Perform the allocation using devm_input_allocate_polled_device().

Quoted 5 lines
Quoted 2 lines
Fixes 8be193c7b1f4 ("Input: add support for PlayStation 1/2 joypads connected via SPI")

This is fixed in the current version of the driver, but you can send it to [email protected] with my

Was it fixed by any specific patch, or just a side-affect of some other larger change?

thanks,

greg k-h

maintainer
#3 lore raw
Quoted 10 lines · Greg Kroah-Hartman
Quoted 9 lines · Dmitry Torokhov

Hi Navid,

Quoted 6 lines · Navid Emamdoost

In the implementation of psxpad_spi_probe() the allocated memory for pdev is leaked if psxpad_spi_init_ff() or input_register_polled_device() fail. The solution is using device managed allocation, like the one used for pad. Perform the allocation using devm_input_allocate_polled_device().

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Fixes 8be193c7b1f4 ("Input: add support for PlayStation 1/2 joypads connected via SPI")

This is fixed in the current version of the driver, but you can send it to [email protected] with my

Was it fixed by any specific patch, or just a side-affect of some other larger change?

It was fixed "by accident" when I converted the driver from using input_polled_dev to standard input device in polled mode.

Thanks.

Signature · 1 line
Dmitry