Create a ahci_get_port_map_helper() helper so that this code can be reused by other module parameters that are saved in a port bitmap. Signed-off-by: Niklas Cassel <cassel@xxxxxxxxxx> --- drivers/ata/ahci.c | 48 +++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index 8d27c567be1c..92b08d3a0c3c 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c @@ -676,35 +676,27 @@ MODULE_PARM_DESC(mask_port_map, "where <pci_dev> is the PCI ID of an AHCI controller in the " "form \"domain:bus:dev.func\""); -static void ahci_apply_port_map_mask(struct device *dev, - struct ahci_host_priv *hpriv, char *mask_s) -{ - unsigned int mask; - - if (kstrtouint(mask_s, 0, &mask)) { - dev_err(dev, "Invalid port map mask\n"); - return; - } - - hpriv->mask_port_map = mask; -} +typedef void (*port_map_callback_t)(struct device *dev, + struct ahci_host_priv *hpriv, char *mask_s); -static void ahci_get_port_map_mask(struct device *dev, - struct ahci_host_priv *hpriv) +static void ahci_get_port_map_helper(struct device *dev, + struct ahci_host_priv *hpriv, + const char *module_str, + port_map_callback_t apply_cb) { char *param, *end, *str, *mask_s; char *name; - if (!strlen(ahci_mask_port_map)) + if (!strlen(module_str)) return; - str = kstrdup(ahci_mask_port_map, GFP_KERNEL); + str = kstrdup(module_str, GFP_KERNEL); if (!str) return; /* Handle single mask case */ if (!strchr(str, '=')) { - ahci_apply_port_map_mask(dev, hpriv, str); + apply_cb(dev, hpriv, str); goto free; } @@ -739,13 +731,33 @@ static void ahci_get_port_map_mask(struct device *dev, param++; } - ahci_apply_port_map_mask(dev, hpriv, mask_s); + apply_cb(dev, hpriv, mask_s); } free: kfree(str); } +static void ahci_apply_port_map_mask(struct device *dev, + struct ahci_host_priv *hpriv, char *mask_s) +{ + unsigned int mask; + + if (kstrtouint(mask_s, 0, &mask)) { + dev_err(dev, "Invalid port map mask\n"); + return; + } + + hpriv->mask_port_map = mask; +} + +static void ahci_get_port_map_mask(struct device *dev, + struct ahci_host_priv *hpriv) +{ + ahci_get_port_map_helper(dev, hpriv, ahci_mask_port_map, + ahci_apply_port_map_mask); +} + static void ahci_pci_save_initial_config(struct pci_dev *pdev, struct ahci_host_priv *hpriv) { -- 2.48.0