Skip to contentSkip to conversation

serial: 8250_mid: Balance reference count for PCI DMA device

PATCH In review Andy Shevchenko 2 participants 7 messages Feb 15, 2022

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

PATCH 1/1 serial: 8250_mid: Balance reference count for PCI DMA device

The pci_get_slot() increases its reference count, the caller must decrement the reference count by calling pci_dev_put().

Fixes 90b9aacf912a ("serial: 8250_pci: add Intel Tangier support")
Fixes f549e94effa1 ("serial: 8250_pci: add Intel Penwell ports")

Depends-on: d9eda9bab237 ("serial: 8250_pci: Intel MID UART support to its own driver")

---
 drivers/tty/serial/8250/8250_mid.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/tty/serial/8250/8250_mid.c +15 -4
index efa0515139f8..e6c1791609dd 100644
@@ -73,6 +73,11 @@ static int pnw_setup(struct mid8250 *mid, struct uart_port *p)
 	return 0;
 }
 
+static void pnw_exit(struct mid8250 *mid)
+{
+	pci_dev_put(mid->dma_dev);
+}
+
 static int tng_handle_irq(struct uart_port *p)
 {
 	struct mid8250 *mid = p->private_data;
@@ -124,6 +129,11 @@ static int tng_setup(struct mid8250 *mid, struct uart_port *p)
 	return 0;
 }
 
+static void tng_exit(struct mid8250 *mid)
+{
+	pci_dev_put(mid->dma_dev);
+}
+
 static int dnv_handle_irq(struct uart_port *p)
 {
 	struct mid8250 *mid = p->private_data;
@@ -330,9 +340,9 @@ static int mid8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	pci_set_drvdata(pdev, mid);
 	return 0;
+
 err:
-	if (mid->board->exit)
-		mid->board->exit(mid);
+	mid->board->exit(mid);
 	return ret;
 }
 
@@ -342,8 +352,7 @@ static void mid8250_remove(struct pci_dev *pdev)
 
 	serial8250_unregister_port(mid->line);
 
-	if (mid->board->exit)
-		mid->board->exit(mid);
+	mid->board->exit(mid);
 }
 
 static const struct mid8250_board pnw_board = {
@@ -351,6 +360,7 @@ static const struct mid8250_board pnw_board = {
 	.freq = 50000000,
 	.base_baud = 115200,
 	.setup = pnw_setup,
+	.exit = pnw_exit,
 };
 
 static const struct mid8250_board tng_board = {
@@ -358,6 +368,7 @@ static const struct mid8250_board tng_board = {
 	.freq = 38400000,
 	.base_baud = 1843200,
 	.setup = tng_setup,
+	.exit = tng_exit,
 };
 
 static const struct mid8250_board dnv_board = {
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 2 lines · Andy Shevchenko

The pci_get_slot() increases its reference count, the caller must decrement the reference count by calling pci_dev_put().

And what about the -EINVAL case?

Quoted 75 lines
Fixes 90b9aacf912a ("serial: 8250_pci: add Intel Tangier support")
Fixes f549e94effa1 ("serial: 8250_pci: add Intel Penwell ports")

Depends-on: d9eda9bab237 ("serial: 8250_pci: Intel MID UART support to its own driver")

---
  drivers/tty/serial/8250/8250_mid.c | 19 +++++++++++++++----
  1 file changed, 15 insertions(+), 4 deletions(-)
drivers/tty/serial/8250/8250_mid.c +15 -4
index efa0515139f8..e6c1791609dd 100644
@@ -73,6 +73,11 @@ static int pnw_setup(struct mid8250 *mid, struct uart_port *p)
  	return 0;
  }
 
+static void pnw_exit(struct mid8250 *mid)
+{
+	pci_dev_put(mid->dma_dev);
+}
+
  static int tng_handle_irq(struct uart_port *p)
  {
  	struct mid8250 *mid = p->private_data;
@@ -124,6 +129,11 @@ static int tng_setup(struct mid8250 *mid, struct uart_port *p)
  	return 0;
  }
 
+static void tng_exit(struct mid8250 *mid)
+{
+	pci_dev_put(mid->dma_dev);
+}
+
  static int dnv_handle_irq(struct uart_port *p)
  {
  	struct mid8250 *mid = p->private_data;
@@ -330,9 +340,9 @@ static int mid8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
  	pci_set_drvdata(pdev, mid);
  	return 0;
+
  err:
-	if (mid->board->exit)
-		mid->board->exit(mid);
+	mid->board->exit(mid);
  	return ret;
  }
 
@@ -342,8 +352,7 @@ static void mid8250_remove(struct pci_dev *pdev)
 
  	serial8250_unregister_port(mid->line);
 
-	if (mid->board->exit)
-		mid->board->exit(mid);
+	mid->board->exit(mid);
  }
 
  static const struct mid8250_board pnw_board = {
@@ -351,6 +360,7 @@ static const struct mid8250_board pnw_board = {
  	.freq = 50000000,
  	.base_baud = 115200,
  	.setup = pnw_setup,
+	.exit = pnw_exit,
  };
 
  static const struct mid8250_board tng_board = {
@@ -358,6 +368,7 @@ static const struct mid8250_board tng_board = {
  	.freq = 38400000,
  	.base_baud = 1843200,
  	.setup = tng_setup,
+	.exit = tng_exit,
  };
 
  static const struct mid8250_board dnv_board = {
Signature · 2 lines
js
suse labs
#2 lore raw
Quoted 5 lines · Jiri Slaby
Quoted 2 lines · Andy Shevchenko

The pci_get_slot() increases its reference count, the caller must decrement the reference count by calling pci_dev_put().

And what about the -EINVAL case?

What about it? The ->probe() calls ->exit() in its error path. Or did I miss something?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Jiri Slaby
Quoted 2 lines · Andy Shevchenko

The pci_get_slot() increases its reference count, the caller must decrement the reference count by calling pci_dev_put().

And what about the -EINVAL case?

What about it? The ->probe() calls ->exit() in its error path. Or did I miss something?

Or you mean that we call pci_dev_put() on NULL pointer? This is completely valid case and handled in the callee.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#4 lore raw
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Jiri Slaby
Quoted 2 lines · Andy Shevchenko

The pci_get_slot() increases its reference count, the caller must decrement the reference count by calling pci_dev_put().

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

And what about the -EINVAL case?

What about it? The ->probe() calls ->exit() in its error path. Or did I miss something?

Or you mean that we call pci_dev_put() on NULL pointer? This is completely valid case and handled in the callee.

No, I mixed up patches :P. This was meant as a comment to "serial: 8250_lpss: Balance reference count for PCI DMA device"

byt_serial_exit() isn't called when byt_serial_setup() fails with EINVAL if I'm looking correctly.

thanks,

Signature · 2 lines
js
suse labs
#5 lore raw
Quoted 12 lines · Jiri Slaby
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Jiri Slaby
Quoted 2 lines · Andy Shevchenko

The pci_get_slot() increases its reference count, the caller must decrement the reference count by calling pci_dev_put().

And what about the -EINVAL case?

What about it? The ->probe() calls ->exit() in its error path. Or did I miss something?

Quoted 8 lines
Quoted 2 lines

Or you mean that we call pci_dev_put() on NULL pointer? This is completely valid case and handled in the callee.

No, I mixed up patches :P. This was meant as a comment to "serial: 8250_lpss: Balance reference count for PCI DMA device"

byt_serial_exit() isn't called when byt_serial_setup() fails with EINVAL if I'm looking correctly.

I see now, thanks for catching this!
I will send a v2 soon.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Jiri Slaby

On 15. 02. 22, 11:31, Andy Shevchenko wrote:

...

Quoted 8 lines
Quoted 5 lines

No, I mixed up patches :P. This was meant as a comment to "serial: 8250_lpss: Balance reference count for PCI DMA device"

byt_serial_exit() isn't called when byt_serial_setup() fails with EINVAL if I'm looking correctly.

I see now, thanks for catching this!
I will send a v2 soon.

What do you think about this patch? Can you give your tag if the code is looking good?

Signature · 2 lines
With Best Regards,
Andy Shevchenko