Skip to content

Commit 477f6ee

Browse files
pnewman-ctigregkh
authored andcommitted
serial: exar: added a exar_get_nr_ports function
Moved code for getting number of ports from exar_pci_probe() to a separate exar_get_nr_ports() function. CTI specific code will be added in another patch in this series. Signed-off-by: Parker Newman <[email protected]> Link: https://lore.kernel.org/r/33f2bf66bc334573c10cf670a299ecef0b7264bc.1713382717.git.pnewman@connecttech.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c69fddf commit 477f6ee

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

drivers/tty/serial/8250/8250_exar.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,21 @@ static irqreturn_t exar_misc_handler(int irq, void *data)
704704
return IRQ_HANDLED;
705705
}
706706

707+
static unsigned int exar_get_nr_ports(struct exar8250_board *board,
708+
struct pci_dev *pcidev)
709+
{
710+
unsigned int nr_ports = 0;
711+
712+
if (pcidev->vendor == PCI_VENDOR_ID_ACCESSIO)
713+
nr_ports = BIT(((pcidev->device & 0x38) >> 3) - 1);
714+
else if (board->num_ports)
715+
nr_ports = board->num_ports;
716+
else
717+
nr_ports = pcidev->device & 0x0f;
718+
719+
return nr_ports;
720+
}
721+
707722
static int
708723
exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
709724
{
@@ -723,12 +738,12 @@ exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
723738

724739
maxnr = pci_resource_len(pcidev, bar) >> (board->reg_shift + 3);
725740

726-
if (pcidev->vendor == PCI_VENDOR_ID_ACCESSIO)
727-
nr_ports = BIT(((pcidev->device & 0x38) >> 3) - 1);
728-
else if (board->num_ports)
729-
nr_ports = board->num_ports;
730-
else
731-
nr_ports = pcidev->device & 0x0f;
741+
nr_ports = exar_get_nr_ports(board, pcidev);
742+
if (nr_ports == 0) {
743+
dev_err_probe(&pcidev->dev, -ENODEV,
744+
"failed to get number of ports\n");
745+
return -ENODEV;
746+
}
732747

733748
priv = devm_kzalloc(&pcidev->dev, struct_size(priv, line, nr_ports), GFP_KERNEL);
734749
if (!priv)

0 commit comments

Comments
 (0)