All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/11] staging: kpc2000: another batch of fixes
@ 2019-05-16 20:04 Jeremy Sowden
  2019-05-16 20:04 ` [PATCH 01/11] staging: kpc2000: removed trailing white-space Jeremy Sowden
                   ` (11 more replies)
  0 siblings, 12 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 20:04 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

These apply on top of the ones I sent earlier this week, which are
currently in the staging-test branch.

There's one white-space patch, a number relating to device attributes
and one that fixes a race affecting the assignment of card numbers.

Jeremy Sowden (11):
  staging: kpc2000: removed trailing white-space.
  staging: kpc2000: add separate show functions for kpc_uio_class device
    attributes.
  staging: kpc2000: define all kpc_uio_class device attributes as
    read-only.
  staging: kpc2000: removed two kpc_uio_class device attributes.
  staging: kpc2000: declare all kpc_uio_class device attributes as
    static.
  staging: kpc2000: use atomic_t to assign card numbers.
  staging: kpc2000: simplified kp2000_device retrieval in device
    attributes call-backs.
  staging: kpc2000: add separate show functions for readable kp device
    attributes.
  staging: kpc2000: formatting fixes for kp device attributes.
  staging: kpc2000: define read-only kp device attributes as read-only.
  staging: kpc2000: declare all kp device attributes as static.

 drivers/staging/kpc2000/TODO                 |   1 -
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 186 ++++++++------
 drivers/staging/kpc2000/kpc2000/core.c       | 253 +++++++++++--------
 drivers/staging/kpc2000/kpc2000/fileops.c    |   2 +-
 drivers/staging/kpc2000/kpc2000/pcie.h       |  10 +-
 5 files changed, 255 insertions(+), 197 deletions(-)

-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH 01/11] staging: kpc2000: removed trailing white-space.
  2019-05-16 20:04 [PATCH 00/11] staging: kpc2000: another batch of fixes Jeremy Sowden
@ 2019-05-16 20:04 ` Jeremy Sowden
  2019-05-16 20:04 ` [PATCH 02/11] staging: kpc2000: add separate show functions for kpc_uio_class device attributes Jeremy Sowden
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 20:04 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Removed trailing white-space from four files.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 62 ++++++-------
 drivers/staging/kpc2000/kpc2000/core.c       | 98 ++++++++++----------
 drivers/staging/kpc2000/kpc2000/fileops.c    |  2 +-
 drivers/staging/kpc2000/kpc2000/pcie.h       | 10 +-
 4 files changed, 86 insertions(+), 86 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index bce2bf9eee04..6a2ebdf20113 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -106,24 +106,24 @@ static int probe_core_basic(unsigned int core_num, struct kp2000_device *pcard,
     };
 
     dev_dbg(&pcard->pdev->dev, "Found Basic core: type = %02d  dma = %02x / %02x  offset = 0x%x  length = 0x%x (%d regs)\n", cte.type, KPC_OLD_S2C_DMA_CH_NUM(cte), KPC_OLD_C2S_DMA_CH_NUM(cte), cte.offset, cte.length, cte.length / 8);
-    
-    
+
+
     cell.platform_data = &core_pdata;
     cell.pdata_size = sizeof(struct kpc_core_device_platdata);
     cell.num_resources = 2;
-    
+
     memset(&resources, 0, sizeof(resources));
 
     resources[0].start = cte.offset;
     resources[0].end   = cte.offset + (cte.length - 1);
     resources[0].flags = IORESOURCE_MEM;
-    
+
     resources[1].start = pcard->pdev->irq;
     resources[1].end   = pcard->pdev->irq;
     resources[1].flags = IORESOURCE_IRQ;
-    
+
     cell.resources = resources;
-    
+
     return mfd_add_devices(
         PCARD_TO_DEV(pcard),    // parent
         pcard->card_num * 100,  // id
@@ -148,7 +148,7 @@ struct kpc_uio_device {
 static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
 {
     struct kpc_uio_device *kudev = dev_get_drvdata(dev);
-    
+
     #define ATTR_NAME_CMP(v)  (strcmp(v, attr->attr.name) == 0)
     if ATTR_NAME_CMP("offset"){
         return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.offset);
@@ -228,7 +228,7 @@ irqreturn_t  kuio_handler(int irq, struct uio_info *uioinfo)
     struct kpc_uio_device *kudev = uioinfo->priv;
     if (irq != kudev->pcard->pdev->irq)
         return IRQ_NONE;
-    
+
     if (kp2000_check_uio_irq(kudev->pcard, kudev->cte.irq_base_num)){
         writeq((1 << kudev->cte.irq_base_num), kudev->pcard->sysinfo_regs_base + REG_INTERRUPT_ACTIVE); // Clear the active flag
         return IRQ_HANDLED;
@@ -242,7 +242,7 @@ int kuio_irqcontrol(struct uio_info *uioinfo, s32 irq_on)
     struct kpc_uio_device *kudev = uioinfo->priv;
     struct kp2000_device *pcard = kudev->pcard;
     u64 mask;
-    
+
     lock_card(pcard);
     mask = readq(pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
     if (irq_on){
@@ -252,7 +252,7 @@ int kuio_irqcontrol(struct uio_info *uioinfo, s32 irq_on)
     }
     writeq(mask, pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
     unlock_card(pcard);
-    
+
     return 0;
 }
 
@@ -263,18 +263,18 @@ static int probe_core_uio(unsigned int core_num, struct kp2000_device *pcard,
     int rv;
 
     dev_dbg(&pcard->pdev->dev, "Found UIO core:   type = %02d  dma = %02x / %02x  offset = 0x%x  length = 0x%x (%d regs)\n", cte.type, KPC_OLD_S2C_DMA_CH_NUM(cte), KPC_OLD_C2S_DMA_CH_NUM(cte), cte.offset, cte.length, cte.length / 8);
-    
+
     kudev = kzalloc(sizeof(struct kpc_uio_device), GFP_KERNEL);
     if (!kudev){
         dev_err(&pcard->pdev->dev, "probe_core_uio: failed to kzalloc kpc_uio_device\n");
         return -ENOMEM;
     }
-    
+
     INIT_LIST_HEAD(&kudev->list);
     kudev->pcard = pcard;
     kudev->cte = cte;
     kudev->core_num = core_num;
-    
+
     kudev->uioinfo.priv = kudev;
     kudev->uioinfo.name = name;
     kudev->uioinfo.version = "0.0";
@@ -291,7 +291,7 @@ static int probe_core_uio(unsigned int core_num, struct kp2000_device *pcard,
     kudev->uioinfo.mem[0].addr = pci_resource_start(pcard->pdev, REG_BAR) + cte.offset;
     kudev->uioinfo.mem[0].size = (cte.length + PAGE_SIZE-1) & ~(PAGE_SIZE-1); // Round up to nearest PAGE_SIZE boundary
     kudev->uioinfo.mem[0].memtype = UIO_MEM_PHYS;
-    
+
     kudev->dev = device_create(kpc_uio_class, &pcard->pdev->dev, MKDEV(0,0), kudev, "%s.%d.%d.%d", kudev->uioinfo.name, pcard->card_num, cte.type, kudev->core_num);
     if (IS_ERR(kudev->dev)) {
         dev_err(&pcard->pdev->dev, "probe_core_uio device_create failed!\n");
@@ -299,7 +299,7 @@ static int probe_core_uio(unsigned int core_num, struct kp2000_device *pcard,
         return -ENODEV;
     }
     dev_set_drvdata(kudev->dev, kudev);
-    
+
     rv = uio_register_device(kudev->dev, &kudev->uioinfo);
     if (rv){
         dev_err(&pcard->pdev->dev, "probe_core_uio failed uio_register_device: %d\n", rv);
@@ -307,9 +307,9 @@ static int probe_core_uio(unsigned int core_num, struct kp2000_device *pcard,
         kfree(kudev);
         return rv;
     }
-    
+
     list_add_tail(&kudev->list, &pcard->uio_devices_list);
-    
+
     return 0;
 }
 
@@ -320,24 +320,24 @@ static int  create_dma_engine_core(struct kp2000_device *pcard, size_t engine_re
     struct resource  resources[2];
 
     dev_dbg(&pcard->pdev->dev, "create_dma_core(pcard = [%p], engine_regs_offset = %zx, engine_num = %d)\n", pcard, engine_regs_offset, engine_num);
-    
+
     cell.platform_data = NULL;
     cell.pdata_size = 0;
     cell.name = KP_DRIVER_NAME_DMA_CONTROLLER;
     cell.num_resources = 2;
-    
+
     memset(&resources, 0, sizeof(resources));
 
     resources[0].start = engine_regs_offset;
     resources[0].end   = engine_regs_offset + (KPC_DMA_ENGINE_SIZE - 1);
     resources[0].flags = IORESOURCE_MEM;
-    
+
     resources[1].start = irq_num;
     resources[1].end   = irq_num;
     resources[1].flags = IORESOURCE_IRQ;
-    
+
     cell.resources = resources;
-    
+
     return mfd_add_devices(
         PCARD_TO_DEV(pcard),    // parent
         pcard->card_num * 100,  // id
@@ -354,7 +354,7 @@ static int  kp2000_setup_dma_controller(struct kp2000_device *pcard)
     int err;
     unsigned int i;
     u64 capabilities_reg;
-    
+
     // S2C Engines
     for (i = 0 ; i < 32 ; i++){
         capabilities_reg = readq( pcard->dma_bar_base + KPC_DMA_S2C_BASE_OFFSET + (KPC_DMA_ENGINE_SIZE * i) );
@@ -371,9 +371,9 @@ static int  kp2000_setup_dma_controller(struct kp2000_device *pcard)
             if (err) goto err_out;
         }
     }
-    
+
     return 0;
-    
+
 err_out:
     dev_err(&pcard->pdev->dev, "kp2000_setup_dma_controller: failed to add a DMA Engine: %d\n", err);
     return err;
@@ -389,12 +389,12 @@ int  kp2000_probe_cores(struct kp2000_device *pcard)
     struct core_table_entry cte;
 
     dev_dbg(&pcard->pdev->dev, "kp2000_probe_cores(pcard = %p / %d)\n", pcard, pcard->card_num);
-    
+
     err = kp2000_setup_dma_controller(pcard);
     if (err) return err;
-    
+
     INIT_LIST_HEAD(&pcard->uio_devices_list);
-    
+
     // First, iterate the core table looking for the highest CORE_ID
     for (i = 0 ; i < pcard->core_table_length ; i++){
         read_val = readq(pcard->sysinfo_regs_base + ((pcard->core_table_offset + i) * 8));
@@ -415,7 +415,7 @@ int  kp2000_probe_cores(struct kp2000_device *pcard)
         for (i = 0 ; i < pcard->core_table_length ; i++){
             read_val = readq(pcard->sysinfo_regs_base + ((pcard->core_table_offset + i) * 8));
             parse_core_table_entry(&cte, read_val, pcard->core_table_rev);
-            
+
             if (cte.type != current_type_id)
                 continue;
 
@@ -443,7 +443,7 @@ int  kp2000_probe_cores(struct kp2000_device *pcard)
             core_num++;
         }
     }
-    
+
     // Finally, instantiate a UIO device for the core_table.
     cte.type                = 0; // CORE_ID_BOARD_INFO
     cte.offset              = 0; // board info is always at the beginning
@@ -459,7 +459,7 @@ int  kp2000_probe_cores(struct kp2000_device *pcard)
         dev_err(&pcard->pdev->dev, "kp2000_probe_cores: failed to add board_info core: %d\n", err);
         goto error;
     }
-    
+
     return 0;
 
 error:
diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index 40390cdd3c8d..eb8bac62d33d 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -30,7 +30,7 @@ static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, cha
     if (!pdev)  return -ENXIO;
     pcard = pci_get_drvdata(pdev);
     if (!pcard)  return -ENXIO;
-    
+
     if (strcmp("ssid", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);  } else
     if (strcmp("ddna", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);  } else
     if (strcmp("card_id", attr->attr.name) == 0){      return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);  } else
@@ -67,11 +67,11 @@ static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *att
     if (!pdev)  return -ENXIO;
     pcard = pci_get_drvdata(pdev);
     if (!pcard)  return -ENXIO;
-    
+
     rv = kstrtol(buf, 0, &wr_val);
     if (rv < 0)  return rv;
     if (wr_val > 7)  return -EINVAL;
-    
+
     wr_val = wr_val << 8;
     wr_val |= 0x1; // Set the "Configure Go" bit
     writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
@@ -111,12 +111,12 @@ static void wait_and_read_ssid(struct kp2000_device *pcard)
 {
     u64 read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
     unsigned long timeout;
-    
+
     if (read_val & 0x8000000000000000){
         pcard->ssid = read_val;
         return;
     }
-    
+
     timeout = jiffies + (HZ * 2);
     do {
         read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
@@ -127,9 +127,9 @@ static void wait_and_read_ssid(struct kp2000_device *pcard)
         cpu_relax();
         //schedule();
     } while (time_before(jiffies, timeout));
-    
+
     dev_notice(&pcard->pdev->dev, "SSID didn't show up!\n");
-    
+
     #if 0
     // Timed out waiting for the SSID to show up, just use the DDNA instead?
     read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
@@ -143,34 +143,34 @@ static void wait_and_read_ssid(struct kp2000_device *pcard)
 static int  read_system_regs(struct kp2000_device *pcard)
 {
     u64 read_val;
-    
+
     read_val = readq(pcard->sysinfo_regs_base + REG_MAGIC_NUMBER);
     if (read_val != KP2000_MAGIC_VALUE){
         dev_err(&pcard->pdev->dev, "Invalid magic!  Got: 0x%016llx  Want: 0x%016lx\n", read_val, KP2000_MAGIC_VALUE);
         return -EILSEQ;
     }
-    
+
     read_val = readq(pcard->sysinfo_regs_base + REG_CARD_ID_AND_BUILD);
     pcard->card_id = (read_val & 0xFFFFFFFF00000000) >> 32;
     pcard->build_version = (read_val & 0x00000000FFFFFFFF) >> 0;
-    
+
     read_val = readq(pcard->sysinfo_regs_base + REG_DATE_AND_TIME_STAMPS);
     pcard->build_datestamp = (read_val & 0xFFFFFFFF00000000) >> 32;
     pcard->build_timestamp = (read_val & 0x00000000FFFFFFFF) >> 0;
-    
+
     read_val = readq(pcard->sysinfo_regs_base + REG_CORE_TABLE_OFFSET);
     pcard->core_table_length = (read_val & 0xFFFFFFFF00000000) >> 32;
     pcard->core_table_offset = (read_val & 0x00000000FFFFFFFF) >> 0;
-    
+
     wait_and_read_ssid(pcard);
-    
+
     read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_HW_ID);
     pcard->core_table_rev    = (read_val & 0x0000000000000F00) >> 8;
     pcard->hardware_revision = (read_val & 0x000000000000001F);
-    
+
     read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
     pcard->ddna = read_val;
-    
+
     dev_info(&pcard->pdev->dev, "system_regs: %08x %08x %08x %08x  %02x  %d %d  %016llx  %016llx\n",
         pcard->card_id,
         pcard->build_version,
@@ -182,12 +182,12 @@ static int  read_system_regs(struct kp2000_device *pcard)
         pcard->ssid,
         pcard->ddna
     );
-    
+
     if (pcard->core_table_rev > 1){
         dev_err(&pcard->pdev->dev, "core table entry revision is higher than we can deal with, cannot continue with this card!\n");
         return 1;
     }
-    
+
     return 0;
 }
 
@@ -209,9 +209,9 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     unsigned long dma_bar_phys_addr;
     unsigned long dma_bar_phys_len;
     u16 regval;
- 
+
     dev_dbg(&pdev->dev, "kp2000_pcie_probe(pdev = [%p], id = [%p])\n", pdev, id);
-    
+
     //{ Step 1: Allocate a struct for the pcard
     pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);
     if (NULL == pcard){
@@ -220,19 +220,19 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     }
     dev_dbg(&pdev->dev, "probe: allocated struct kp2000_device @ %p\n", pcard);
     //}
-    
+
     //{ Step 2: Initialize trivial pcard elements
     pcard->card_num = card_count;
     card_count++;
     scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
-    
+
     mutex_init(&pcard->sem);
     lock_card(pcard);
-    
+
     pcard->pdev = pdev;
     pci_set_drvdata(pdev, pcard);
     //}
-    
+
     //{ Step 3: Enable PCI device
     err = pci_enable_device(pcard->pdev);
     if (err){
@@ -240,11 +240,11 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
         goto out3;
     }
     //}
-    
+
     //{ Step 4: Setup the Register BAR
     reg_bar_phys_addr = pci_resource_start(pcard->pdev, REG_BAR);
     reg_bar_phys_len = pci_resource_len(pcard->pdev, REG_BAR);
-    
+
     pcard->regs_bar_base = ioremap_nocache(reg_bar_phys_addr, PAGE_SIZE);
     if (NULL == pcard->regs_bar_base){
         dev_err(&pcard->pdev->dev, "probe: REG_BAR could not remap memory to virtual space\n");
@@ -252,7 +252,7 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
         goto out4;
     }
     dev_dbg(&pcard->pdev->dev, "probe: REG_BAR virt hardware address start [%p]\n", pcard->regs_bar_base);
-    
+
     err = pci_request_region(pcard->pdev, REG_BAR, KP_DRIVER_NAME_KP2000);
     if (err){
         iounmap(pcard->regs_bar_base);
@@ -260,16 +260,16 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
         err = -ENODEV;
         goto out4;
     }
-    
+
     pcard->regs_base_resource.start = reg_bar_phys_addr;
     pcard->regs_base_resource.end   = reg_bar_phys_addr + reg_bar_phys_len - 1;
     pcard->regs_base_resource.flags = IORESOURCE_MEM;
     //}
-    
+
     //{ Step 5: Setup the DMA BAR
     dma_bar_phys_addr = pci_resource_start(pcard->pdev, DMA_BAR);
     dma_bar_phys_len = pci_resource_len(pcard->pdev, DMA_BAR);
-    
+
     pcard->dma_bar_base = ioremap_nocache(dma_bar_phys_addr, dma_bar_phys_len);
     if (NULL == pcard->dma_bar_base){
         dev_err(&pcard->pdev->dev, "probe: DMA_BAR could not remap memory to virtual space\n");
@@ -277,9 +277,9 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
         goto out5;
     }
     dev_dbg(&pcard->pdev->dev, "probe: DMA_BAR virt hardware address start [%p]\n", pcard->dma_bar_base);
-    
+
     pcard->dma_common_regs = pcard->dma_bar_base + KPC_DMA_COMMON_OFFSET;
-    
+
     err = pci_request_region(pcard->pdev, DMA_BAR, "kp2000_pcie");
     if (err){
         iounmap(pcard->dma_bar_base);
@@ -287,22 +287,22 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
         err = -ENODEV;
         goto out5;
     }
-    
+
     pcard->dma_base_resource.start = dma_bar_phys_addr;
     pcard->dma_base_resource.end   = dma_bar_phys_addr + dma_bar_phys_len - 1;
     pcard->dma_base_resource.flags = IORESOURCE_MEM;
     //}
-    
+
     //{ Step 6: System Regs
     pcard->sysinfo_regs_base = pcard->regs_bar_base;
     err = read_system_regs(pcard);
     if (err)
         goto out6;
-    
+
     // Disable all "user" interrupts because they're not used yet.
     writeq(0xFFFFFFFFFFFFFFFF, pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
     //}
-    
+
     //{ Step 7: Configure PCI thingies
     // let the card master PCIe
     pci_set_master(pcard->pdev);
@@ -310,19 +310,19 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     pci_read_config_word(pcard->pdev, PCI_COMMAND, &regval);
     regval |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
     pci_write_config_word(pcard->pdev, PCI_COMMAND, regval);
-    
+
     // Clear relaxed ordering bit
     pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN, 0);
-    
+
     // Set Max_Payload_Size and Max_Read_Request_Size
     regval = (0x0) << 5; // Max_Payload_Size = 128 B
     pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_PAYLOAD, regval);
     regval = (0x0) << 12; // Max_Read_Request_Size = 128 B
     pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_READRQ, regval);
-    
+
     // Enable error reporting for: Correctable Errors, Non-Fatal Errors, Fatal Errors, Unsupported Requests
     pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, 0, PCI_EXP_DEVCTL_CERE | PCI_EXP_DEVCTL_NFERE | PCI_EXP_DEVCTL_FERE | PCI_EXP_DEVCTL_URRE);
-    
+
     err = dma_set_mask(PCARD_TO_DEV(pcard), DMA_BIT_MASK(64));
     if (err){
         dev_err(&pcard->pdev->dev, "CANNOT use DMA mask %0llx\n", DMA_BIT_MASK(64));
@@ -330,19 +330,19 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     }
     dev_dbg(&pcard->pdev->dev, "Using DMA mask %0llx\n", dma_get_mask(PCARD_TO_DEV(pcard)));
     //}
-    
+
     //{ Step 8: Configure IRQs
     err = pci_enable_msi(pcard->pdev);
     if (err < 0)
         goto out8a;
-    
+
     rv = request_irq(pcard->pdev->irq, kp2000_irq_handler, IRQF_SHARED, pcard->name, pcard);
     if (rv){
         dev_err(&pcard->pdev->dev, "kp2000_pcie_probe: failed to request_irq: %d\n", rv);
         goto out8b;
     }
     //}
-    
+
     //{ Step 9: Setup sysfs attributes
     err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);
     if (err){
@@ -350,30 +350,30 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
         goto out9;
     }
     //}
-    
+
     //{ Step 10: Setup misc device
     pcard->miscdev.minor = MISC_DYNAMIC_MINOR;
     pcard->miscdev.fops = &kp2000_fops;
     pcard->miscdev.parent = &pcard->pdev->dev;
     pcard->miscdev.name = pcard->name;
-    
+
     err = misc_register(&pcard->miscdev);
     if (err){
         dev_err(&pcard->pdev->dev, "kp2000_pcie_probe: misc_register failed: %d\n", err);
         goto out10;
     }
     //}
-    
+
     //{ Step 11: Probe cores
     err = kp2000_probe_cores(pcard);
     if (err)
         goto out11;
     //}
-    
+
     //{ Step 12: Enable IRQs in HW
     SetBackEndControl(pcard->dma_common_regs, KPC_DMA_CARD_IRQ_ENABLE | KPC_DMA_CARD_USER_INTERRUPT_MODE);
     //}
-    
+
     dev_dbg(&pcard->pdev->dev, "kp2000_pcie_probe() complete!\n");
     unlock_card(pcard);
     return 0;
@@ -410,9 +410,9 @@ void  kp2000_pcie_remove(struct pci_dev *pdev)
     struct kp2000_device *pcard = pci_get_drvdata(pdev);
 
     dev_dbg(&pdev->dev, "kp2000_pcie_remove(pdev=%p)\n", pdev);
-    
+
     if (pcard == NULL)  return;
-    
+
     lock_card(pcard);
     kp2000_remove_cores(pcard);
     mfd_remove_devices(PCARD_TO_DEV(pcard));
diff --git a/drivers/staging/kpc2000/kpc2000/fileops.c b/drivers/staging/kpc2000/kpc2000/fileops.c
index b3b0b763fa1e..3e3b4800bc2c 100644
--- a/drivers/staging/kpc2000/kpc2000/fileops.c
+++ b/drivers/staging/kpc2000/kpc2000/fileops.c
@@ -88,7 +88,7 @@ long  kp2000_cdev_ioctl(struct file *filp, unsigned int ioctl_num, unsigned long
 	switch (ioctl_num){
 	case KP2000_IOCTL_GET_CPLD_REG:             return readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	case KP2000_IOCTL_GET_PCIE_ERROR_REG:       return readq(pcard->sysinfo_regs_base + REG_PCIE_ERROR_COUNT);
-    
+
 	case KP2000_IOCTL_GET_EVERYTHING: {
 		struct kp2000_regs temp;
 		int ret;
diff --git a/drivers/staging/kpc2000/kpc2000/pcie.h b/drivers/staging/kpc2000/kpc2000/pcie.h
index 893aebfd1449..8a032a5a962e 100644
--- a/drivers/staging/kpc2000/kpc2000/pcie.h
+++ b/drivers/staging/kpc2000/kpc2000/pcie.h
@@ -52,17 +52,17 @@ struct kp2000_device {
     struct pci_dev     *pdev;
     struct miscdevice   miscdev;
     char                name[16];
-    
+
     unsigned int        card_num;
     struct mutex        sem;
-    
+
     void __iomem       *sysinfo_regs_base;
     void __iomem       *regs_bar_base;
     struct resource     regs_base_resource;
     void __iomem       *dma_bar_base;
     void __iomem       *dma_common_regs;
     struct resource     dma_base_resource;
-    
+
     // "System Registers"
     u32                 card_id;
     u32                 build_version;
@@ -74,10 +74,10 @@ struct kp2000_device {
     u8                  hardware_revision;
     u64                 ssid;
     u64                 ddna;
-    
+
     // IRQ stuff
     unsigned int        irq;
-    
+
     struct list_head    uio_devices_list;
 };
 
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 02/11] staging: kpc2000: add separate show functions for kpc_uio_class device attributes.
  2019-05-16 20:04 [PATCH 00/11] staging: kpc2000: another batch of fixes Jeremy Sowden
  2019-05-16 20:04 ` [PATCH 01/11] staging: kpc2000: removed trailing white-space Jeremy Sowden
@ 2019-05-16 20:04 ` Jeremy Sowden
  2019-05-16 20:17   ` Matt Sickler
  2019-05-16 20:45   ` Greg KH
  2019-05-16 20:04 ` [PATCH 03/11] staging: kpc2000: define all kpc_uio_class device attributes as read-only Jeremy Sowden
                   ` (9 subsequent siblings)
  11 siblings, 2 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 20:04 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Define separate simple show functions for each attribute instead of
having a one big one containing a chain of conditionals.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 138 ++++++++++++-------
 1 file changed, 92 insertions(+), 46 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index 6a2ebdf20113..101eb23caaac 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -145,55 +145,102 @@ struct kpc_uio_device {
     u16 core_num;
 };
 
-static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t offset_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
 {
-    struct kpc_uio_device *kudev = dev_get_drvdata(dev);
-
-    #define ATTR_NAME_CMP(v)  (strcmp(v, attr->attr.name) == 0)
-    if ATTR_NAME_CMP("offset"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.offset);
-    } else if ATTR_NAME_CMP("size"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.length);
-    } else if ATTR_NAME_CMP("type"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.type);
-    }
-    else if ATTR_NAME_CMP("s2c_dma"){
-        if (kudev->cte.s2c_dma_present){
-            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.s2c_dma_channel_num);
-        } else {
-            return scnprintf(buf, PAGE_SIZE, "not present\n");
-        }
-    } else if ATTR_NAME_CMP("c2s_dma"){
-        if (kudev->cte.c2s_dma_present){
-            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.c2s_dma_channel_num);
-        } else {
-            return scnprintf(buf, PAGE_SIZE, "not present\n");
-        }
-    }
-    else if ATTR_NAME_CMP("irq_count"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_count);
-    } else if ATTR_NAME_CMP("irq_base_num"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_base_num);
-    } else if ATTR_NAME_CMP("core_num"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->core_num);
-    } else {
-        return 0;
-    }
-    #undef ATTR_NAME_CMP
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.offset);
+}
+
+static ssize_t size_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.length);
 }
 
+static ssize_t type_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.type);
+}
+
+static ssize_t s2c_dma_ch_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	return 0;
+}
+
+static ssize_t c2s_dma_ch_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	return 0;
+}
+
+static ssize_t s2c_dma_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
 
-DEVICE_ATTR(offset,  0444, show_attr, NULL);
-DEVICE_ATTR(size,    0444, show_attr, NULL);
-DEVICE_ATTR(type,    0444, show_attr, NULL);
-DEVICE_ATTR(s2c_dma_ch, 0444, show_attr, NULL);
-DEVICE_ATTR(c2s_dma_ch, 0444, show_attr, NULL);
-DEVICE_ATTR(s2c_dma, 0444, show_attr, NULL);
-DEVICE_ATTR(c2s_dma, 0444, show_attr, NULL);
-DEVICE_ATTR(irq_count, 0444, show_attr, NULL);
-DEVICE_ATTR(irq_base_num, 0444, show_attr, NULL);
-DEVICE_ATTR(core_num, 0444, show_attr, NULL);
-struct attribute * kpc_uio_class_attrs[] = {
+	if (!kudev->cte.s2c_dma_present)
+		return scnprintf(buf, PAGE_SIZE, "not present\n");
+
+	return scnprintf(buf, PAGE_SIZE, "%u\n",
+			 kudev->cte.s2c_dma_channel_num);
+}
+
+static ssize_t c2s_dma_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	if (!kudev->cte.c2s_dma_present)
+		return scnprintf(buf, PAGE_SIZE, "not present\n");
+
+	return scnprintf(buf, PAGE_SIZE, "%u\n",
+			 kudev->cte.c2s_dma_channel_num);
+}
+
+static ssize_t irq_count_show(struct device *dev, struct device_attribute *attr,
+			      char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_count);
+}
+
+static ssize_t irq_base_num_show(struct device *dev,
+				 struct device_attribute *attr, char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_base_num);
+}
+
+static ssize_t core_num_show(struct device *dev, struct device_attribute *attr,
+			     char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->core_num);
+}
+
+DEVICE_ATTR(offset,       0444, offset_show,       NULL);
+DEVICE_ATTR(size,         0444, size_show,         NULL);
+DEVICE_ATTR(type,         0444, type_show,         NULL);
+DEVICE_ATTR(s2c_dma_ch,   0444, s2c_dma_ch_show,   NULL);
+DEVICE_ATTR(c2s_dma_ch,   0444, c2s_dma_ch_show,   NULL);
+DEVICE_ATTR(s2c_dma,      0444, s2c_dma_show,      NULL);
+DEVICE_ATTR(c2s_dma,      0444, c2s_dma_show,      NULL);
+DEVICE_ATTR(irq_count,    0444, irq_count_show,    NULL);
+DEVICE_ATTR(irq_base_num, 0444, irq_base_num_show, NULL);
+DEVICE_ATTR(core_num,     0444, core_num_show,     NULL);
+
+struct attribute *kpc_uio_class_attrs[] = {
 	&dev_attr_offset.attr,
 	&dev_attr_size.attr,
 	&dev_attr_type.attr,
@@ -207,7 +254,6 @@ struct attribute * kpc_uio_class_attrs[] = {
 	NULL,
 };
 
-
 static
 int  kp2000_check_uio_irq(struct kp2000_device *pcard, u32 irq_num)
 {
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 03/11] staging: kpc2000: define all kpc_uio_class device attributes as read-only.
  2019-05-16 20:04 [PATCH 00/11] staging: kpc2000: another batch of fixes Jeremy Sowden
  2019-05-16 20:04 ` [PATCH 01/11] staging: kpc2000: removed trailing white-space Jeremy Sowden
  2019-05-16 20:04 ` [PATCH 02/11] staging: kpc2000: add separate show functions for kpc_uio_class device attributes Jeremy Sowden
@ 2019-05-16 20:04 ` Jeremy Sowden
  2019-05-16 20:04 ` [PATCH 04/11] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 20:04 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

All of the device attributes are read-only, so use DEVICE_ATTR_RO to
define them.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index 101eb23caaac..da15ae5b5a3d 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -229,16 +229,16 @@ static ssize_t core_num_show(struct device *dev, struct device_attribute *attr,
 	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->core_num);
 }
 
-DEVICE_ATTR(offset,       0444, offset_show,       NULL);
-DEVICE_ATTR(size,         0444, size_show,         NULL);
-DEVICE_ATTR(type,         0444, type_show,         NULL);
-DEVICE_ATTR(s2c_dma_ch,   0444, s2c_dma_ch_show,   NULL);
-DEVICE_ATTR(c2s_dma_ch,   0444, c2s_dma_ch_show,   NULL);
-DEVICE_ATTR(s2c_dma,      0444, s2c_dma_show,      NULL);
-DEVICE_ATTR(c2s_dma,      0444, c2s_dma_show,      NULL);
-DEVICE_ATTR(irq_count,    0444, irq_count_show,    NULL);
-DEVICE_ATTR(irq_base_num, 0444, irq_base_num_show, NULL);
-DEVICE_ATTR(core_num,     0444, core_num_show,     NULL);
+DEVICE_ATTR_RO(offset);
+DEVICE_ATTR_RO(size);
+DEVICE_ATTR_RO(type);
+DEVICE_ATTR_RO(s2c_dma_ch);
+DEVICE_ATTR_RO(c2s_dma_ch);
+DEVICE_ATTR_RO(s2c_dma);
+DEVICE_ATTR_RO(c2s_dma);
+DEVICE_ATTR_RO(irq_count);
+DEVICE_ATTR_RO(irq_base_num);
+DEVICE_ATTR_RO(core_num);
 
 struct attribute *kpc_uio_class_attrs[] = {
 	&dev_attr_offset.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 04/11] staging: kpc2000: removed two kpc_uio_class device attributes.
  2019-05-16 20:04 [PATCH 00/11] staging: kpc2000: another batch of fixes Jeremy Sowden
                   ` (2 preceding siblings ...)
  2019-05-16 20:04 ` [PATCH 03/11] staging: kpc2000: define all kpc_uio_class device attributes as read-only Jeremy Sowden
@ 2019-05-16 20:04 ` Jeremy Sowden
  2019-05-16 20:04 ` [PATCH 05/11] staging: kpc2000: declare all kpc_uio_class device attributes as static Jeremy Sowden
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 20:04 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

The show functions of two attributes output nothing.  Removed them.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index da15ae5b5a3d..38c3738209a7 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -169,18 +169,6 @@ static ssize_t type_show(struct device *dev, struct device_attribute *attr,
 	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.type);
 }
 
-static ssize_t s2c_dma_ch_show(struct device *dev,
-			       struct device_attribute *attr, char *buf)
-{
-	return 0;
-}
-
-static ssize_t c2s_dma_ch_show(struct device *dev,
-			       struct device_attribute *attr, char *buf)
-{
-	return 0;
-}
-
 static ssize_t s2c_dma_show(struct device *dev, struct device_attribute *attr,
 			    char *buf)
 {
@@ -232,8 +220,6 @@ static ssize_t core_num_show(struct device *dev, struct device_attribute *attr,
 DEVICE_ATTR_RO(offset);
 DEVICE_ATTR_RO(size);
 DEVICE_ATTR_RO(type);
-DEVICE_ATTR_RO(s2c_dma_ch);
-DEVICE_ATTR_RO(c2s_dma_ch);
 DEVICE_ATTR_RO(s2c_dma);
 DEVICE_ATTR_RO(c2s_dma);
 DEVICE_ATTR_RO(irq_count);
@@ -244,8 +230,6 @@ struct attribute *kpc_uio_class_attrs[] = {
 	&dev_attr_offset.attr,
 	&dev_attr_size.attr,
 	&dev_attr_type.attr,
-	&dev_attr_s2c_dma_ch.attr,
-	&dev_attr_c2s_dma_ch.attr,
 	&dev_attr_s2c_dma.attr,
 	&dev_attr_c2s_dma.attr,
 	&dev_attr_irq_count.attr,
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 05/11] staging: kpc2000: declare all kpc_uio_class device attributes as static.
  2019-05-16 20:04 [PATCH 00/11] staging: kpc2000: another batch of fixes Jeremy Sowden
                   ` (3 preceding siblings ...)
  2019-05-16 20:04 ` [PATCH 04/11] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
@ 2019-05-16 20:04 ` Jeremy Sowden
  2019-05-16 20:04 ` [PATCH 06/11] staging: kpc2000: use atomic_t to assign card numbers Jeremy Sowden
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 20:04 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

The definitions are only used to populate the kpc_uio_class_attrs
attribute array, so declare them as static.

Fixes the following sparse warnings:

  drivers/staging/kpc2000/kpc2000/cell_probe.c:220:1: warning: symbol 'dev_attr_offset' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:221:1: warning: symbol 'dev_attr_size' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:222:1: warning: symbol 'dev_attr_type' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:223:1: warning: symbol 'dev_attr_s2c_dma' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:224:1: warning: symbol 'dev_attr_c2s_dma' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:225:1: warning: symbol 'dev_attr_irq_count' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:226:1: warning: symbol 'dev_attr_irq_base_num' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:227:1: warning: symbol 'dev_attr_core_num' was not declared. Should it be static?

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index 38c3738209a7..4a1fec7f563b 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -217,14 +217,14 @@ static ssize_t core_num_show(struct device *dev, struct device_attribute *attr,
 	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->core_num);
 }
 
-DEVICE_ATTR_RO(offset);
-DEVICE_ATTR_RO(size);
-DEVICE_ATTR_RO(type);
-DEVICE_ATTR_RO(s2c_dma);
-DEVICE_ATTR_RO(c2s_dma);
-DEVICE_ATTR_RO(irq_count);
-DEVICE_ATTR_RO(irq_base_num);
-DEVICE_ATTR_RO(core_num);
+static DEVICE_ATTR_RO(offset);
+static DEVICE_ATTR_RO(size);
+static DEVICE_ATTR_RO(type);
+static DEVICE_ATTR_RO(s2c_dma);
+static DEVICE_ATTR_RO(c2s_dma);
+static DEVICE_ATTR_RO(irq_count);
+static DEVICE_ATTR_RO(irq_base_num);
+static DEVICE_ATTR_RO(core_num);
 
 struct attribute *kpc_uio_class_attrs[] = {
 	&dev_attr_offset.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 06/11] staging: kpc2000: use atomic_t to assign card numbers.
  2019-05-16 20:04 [PATCH 00/11] staging: kpc2000: another batch of fixes Jeremy Sowden
                   ` (4 preceding siblings ...)
  2019-05-16 20:04 ` [PATCH 05/11] staging: kpc2000: declare all kpc_uio_class device attributes as static Jeremy Sowden
@ 2019-05-16 20:04 ` Jeremy Sowden
  2019-05-16 20:04 ` [PATCH 07/11] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs Jeremy Sowden
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 20:04 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Previously the next card number was assigned from a static int local
variable, which was read and later incremented.  This was not thread-
safe, so now we use an atomic_t and atomic_fetch_add instead.

Updated TODO.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/TODO           | 1 -
 drivers/staging/kpc2000/kpc2000/core.c | 7 ++++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/kpc2000/TODO b/drivers/staging/kpc2000/TODO
index 669fe5bf9637..47530e23e940 100644
--- a/drivers/staging/kpc2000/TODO
+++ b/drivers/staging/kpc2000/TODO
@@ -1,6 +1,5 @@
 - the kpc_spi driver doesn't seem to let multiple transactions (to different instances of the core) happen in parallel...
 - The kpc_i2c driver is a hot mess, it should probably be cleaned up a ton.  It functions against current hardware though.
-- pcard->card_num in kp2000_pcie_probe() is a global variable and needs atomic / locking / something better.
 - would be nice if the AIO fileops in kpc_dma could be made to work
     - probably want to add a CONFIG_ option to control compilation of the AIO functions
 - if the AIO fileops in kpc_dma start working, next would be making iov_count > 1 work too
diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index eb8bac62d33d..72130a50afd6 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0+
+#include <linux/atomic.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/pci.h>
@@ -19,6 +20,8 @@
 #include "pcie.h"
 
 
+static atomic_t next_card_num = ATOMIC_INIT(1);
+
 /*******************************************************
   * SysFS Attributes
   ******************************************************/
@@ -202,7 +205,6 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
     int err = 0;
     struct kp2000_device *pcard;
-    static int card_count = 1;
     int rv;
     unsigned long reg_bar_phys_addr;
     unsigned long reg_bar_phys_len;
@@ -222,8 +224,7 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     //}
 
     //{ Step 2: Initialize trivial pcard elements
-    pcard->card_num = card_count;
-    card_count++;
+    pcard->card_num = atomic_fetch_add(1, &next_card_num);
     scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
 
     mutex_init(&pcard->sem);
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 07/11] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs.
  2019-05-16 20:04 [PATCH 00/11] staging: kpc2000: another batch of fixes Jeremy Sowden
                   ` (5 preceding siblings ...)
  2019-05-16 20:04 ` [PATCH 06/11] staging: kpc2000: use atomic_t to assign card numbers Jeremy Sowden
@ 2019-05-16 20:04 ` Jeremy Sowden
  2019-05-16 20:04 ` [PATCH 08/11] staging: kpc2000: add separate show functions for readable kp device attributes Jeremy Sowden
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 20:04 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

The call-backs used the same recipe to get the pcard from dev:

  struct pci_dev *pdev = to_pci_dev(dev);
  struct kp2000_device *pcard;

  if (!pdev) return -ENXIO;
  pcard = pci_get_drvdata(pdev);
  if (!pcard) return -ENXIO;

where to_pci_dev is a wrapper for container_of.

However, pci_set_drvdata is called before the sysfs files are created:

  int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  {
    // ...

    pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);

    // ...

    pcard->pdev = pdev;
    pci_set_drvdata(pdev, pcard);

    // ...

    err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);

Therefore, to_pci_dev and pci_get_drvdata cannot return NULL, and pcard
can be initialized directly from dev:

  struct kp2000_device *pcard = dev_get_drvdata(dev);

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 24 +++---------------------
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index 72130a50afd6..c05864cf33ce 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -27,12 +27,7 @@ static atomic_t next_card_num = ATOMIC_INIT(1);
   ******************************************************/
 static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
-    struct kp2000_device *pcard;
-
-    if (!pdev)  return -ENXIO;
-    pcard = pci_get_drvdata(pdev);
-    if (!pcard)  return -ENXIO;
+    struct kp2000_device *pcard = dev_get_drvdata(dev);
 
     if (strcmp("ssid", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);  } else
     if (strcmp("ddna", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);  } else
@@ -46,31 +41,18 @@ static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, cha
 
 static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
-	struct pci_dev *pdev = to_pci_dev(dev);
-	struct kp2000_device *pcard;
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	u64 val;
 
-	if (!pdev)
-		return -ENXIO;
-
-	pcard = pci_get_drvdata(pdev);
-	if (!pcard)
-		return -ENXIO;
-
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
 }
 static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
+    struct kp2000_device *pcard = dev_get_drvdata(dev);
     long wr_val;
-    struct kp2000_device *pcard;
     int rv;
 
-    if (!pdev)  return -ENXIO;
-    pcard = pci_get_drvdata(pdev);
-    if (!pcard)  return -ENXIO;
-
     rv = kstrtol(buf, 0, &wr_val);
     if (rv < 0)  return rv;
     if (wr_val > 7)  return -EINVAL;
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 08/11] staging: kpc2000: add separate show functions for readable kp device attributes.
  2019-05-16 20:04 [PATCH 00/11] staging: kpc2000: another batch of fixes Jeremy Sowden
                   ` (6 preceding siblings ...)
  2019-05-16 20:04 ` [PATCH 07/11] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs Jeremy Sowden
@ 2019-05-16 20:04 ` Jeremy Sowden
  2019-05-16 20:04 ` [PATCH 09/11] staging: kpc2000: formatting fixes for " Jeremy Sowden
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 20:04 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Define separate simple show functions for each attribute instead of
having a one big one containing a chain of conditionals.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 91 +++++++++++++++++++-------
 1 file changed, 67 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index c05864cf33ce..e7e0d188ff73 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -19,27 +19,70 @@
 #include <linux/jiffies.h>
 #include "pcie.h"
 
-
 static atomic_t next_card_num = ATOMIC_INIT(1);
 
 /*******************************************************
   * SysFS Attributes
   ******************************************************/
-static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
+
+static ssize_t ssid_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
 {
-    struct kp2000_device *pcard = dev_get_drvdata(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);
+}
+
+static ssize_t ddna_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);
+}
+
+static ssize_t card_id_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);
+}
+
+static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-    if (strcmp("ssid", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);  } else
-    if (strcmp("ddna", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);  } else
-    if (strcmp("card_id", attr->attr.name) == 0){      return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);  } else
-    if (strcmp("hw_rev", attr->attr.name) == 0){       return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->hardware_revision);  } else
-    if (strcmp("build", attr->attr.name) == 0){        return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_version);  } else
-    if (strcmp("build_date", attr->attr.name) == 0){   return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_datestamp);  } else
-    if (strcmp("build_time", attr->attr.name) == 0){   return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_timestamp);  } else
-    { return -ENXIO; }
+	return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->hardware_revision);
 }
 
-static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t build_show(struct device *dev, struct device_attribute *attr,
+			  char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_version);
+}
+
+static ssize_t build_date_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_datestamp);
+}
+
+static ssize_t build_time_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_timestamp);
+}
+
+static ssize_t cpld_reg_show(struct device *dev, struct device_attribute *attr,
+			     char *buf)
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	u64 val;
@@ -47,6 +90,7 @@ static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
 }
+
 static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
     struct kp2000_device *pcard = dev_get_drvdata(dev);
@@ -63,18 +107,17 @@ static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *att
     return count;
 }
 
-
-DEVICE_ATTR(ssid,       0444, show_attr, NULL);
-DEVICE_ATTR(ddna,       0444, show_attr, NULL);
-DEVICE_ATTR(card_id,    0444, show_attr, NULL);
-DEVICE_ATTR(hw_rev,     0444, show_attr, NULL);
-DEVICE_ATTR(build,      0444, show_attr, NULL);
-DEVICE_ATTR(build_date, 0444, show_attr, NULL);
-DEVICE_ATTR(build_time, 0444, show_attr, NULL);
-DEVICE_ATTR(cpld_reg,   0444, show_cpld_config_reg, NULL);
-DEVICE_ATTR(cpld_reconfigure,   0220, NULL, cpld_reconfigure);
-
-static const struct attribute *  kp_attr_list[] = {
+DEVICE_ATTR(ssid,             0444, ssid_show,       NULL);
+DEVICE_ATTR(ddna,             0444, ddna_show,       NULL);
+DEVICE_ATTR(card_id,          0444, card_id_show,    NULL);
+DEVICE_ATTR(hw_rev,           0444, hw_rev_show,     NULL);
+DEVICE_ATTR(build,            0444, build_show,      NULL);
+DEVICE_ATTR(build_date,       0444, build_date_show, NULL);
+DEVICE_ATTR(build_time,       0444, build_time_show, NULL);
+DEVICE_ATTR(cpld_reg,         0444, cpld_reg_show,   NULL);
+DEVICE_ATTR(cpld_reconfigure, 0220, NULL,            cpld_reconfigure);
+
+static const struct attribute *kp_attr_list[] = {
     &dev_attr_ssid.attr,
     &dev_attr_ddna.attr,
     &dev_attr_card_id.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 09/11] staging: kpc2000: formatting fixes for kp device attributes.
  2019-05-16 20:04 [PATCH 00/11] staging: kpc2000: another batch of fixes Jeremy Sowden
                   ` (7 preceding siblings ...)
  2019-05-16 20:04 ` [PATCH 08/11] staging: kpc2000: add separate show functions for readable kp device attributes Jeremy Sowden
@ 2019-05-16 20:04 ` Jeremy Sowden
  2019-05-16 20:04 ` [PATCH 10/11] staging: kpc2000: define read-only kp device attributes as read-only Jeremy Sowden
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 20:04 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Fixed indentation of cpld_reconfigure store call-back and definition of
attribute list.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 51 ++++++++++++++------------
 1 file changed, 27 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index e7e0d188ff73..7a5dd5f2300b 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -91,20 +91,24 @@ static ssize_t cpld_reg_show(struct device *dev, struct device_attribute *attr,
 	return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
 }
 
-static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+static ssize_t cpld_reconfigure(struct device *dev,
+				struct device_attribute *attr,
+				const char *buf, size_t count)
 {
-    struct kp2000_device *pcard = dev_get_drvdata(dev);
-    long wr_val;
-    int rv;
-
-    rv = kstrtol(buf, 0, &wr_val);
-    if (rv < 0)  return rv;
-    if (wr_val > 7)  return -EINVAL;
-
-    wr_val = wr_val << 8;
-    wr_val |= 0x1; // Set the "Configure Go" bit
-    writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
-    return count;
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+	long wr_val;
+	int rv;
+
+	rv = kstrtol(buf, 0, &wr_val);
+	if (rv < 0)
+		return rv;
+	if (wr_val > 7)
+		return -EINVAL;
+
+	wr_val = wr_val << 8;
+	wr_val |= 0x1; // Set the "Configure Go" bit
+	writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
+	return count;
 }
 
 DEVICE_ATTR(ssid,             0444, ssid_show,       NULL);
@@ -118,19 +122,18 @@ DEVICE_ATTR(cpld_reg,         0444, cpld_reg_show,   NULL);
 DEVICE_ATTR(cpld_reconfigure, 0220, NULL,            cpld_reconfigure);
 
 static const struct attribute *kp_attr_list[] = {
-    &dev_attr_ssid.attr,
-    &dev_attr_ddna.attr,
-    &dev_attr_card_id.attr,
-    &dev_attr_hw_rev.attr,
-    &dev_attr_build.attr,
-    &dev_attr_build_date.attr,
-    &dev_attr_build_time.attr,
-    &dev_attr_cpld_reg.attr,
-    &dev_attr_cpld_reconfigure.attr,
-    NULL,
+	&dev_attr_ssid.attr,
+	&dev_attr_ddna.attr,
+	&dev_attr_card_id.attr,
+	&dev_attr_hw_rev.attr,
+	&dev_attr_build.attr,
+	&dev_attr_build_date.attr,
+	&dev_attr_build_time.attr,
+	&dev_attr_cpld_reg.attr,
+	&dev_attr_cpld_reconfigure.attr,
+	NULL,
 };
 
-
 /*******************************************************
   * Functions
   ******************************************************/
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 10/11] staging: kpc2000: define read-only kp device attributes as read-only.
  2019-05-16 20:04 [PATCH 00/11] staging: kpc2000: another batch of fixes Jeremy Sowden
                   ` (8 preceding siblings ...)
  2019-05-16 20:04 ` [PATCH 09/11] staging: kpc2000: formatting fixes for " Jeremy Sowden
@ 2019-05-16 20:04 ` Jeremy Sowden
  2019-05-16 20:04 ` [PATCH 11/11] staging: kpc2000: declare all kp device attributes as static Jeremy Sowden
  2019-05-16 21:38 ` [PATCH v2 0/9] staging: kpc2000: another batch of fixes Jeremy Sowden
  11 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 20:04 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Most of the device attributes are read-only, so use DEVICE_ATTR_RO
to define them.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index 7a5dd5f2300b..55e9038117a4 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -111,15 +111,15 @@ static ssize_t cpld_reconfigure(struct device *dev,
 	return count;
 }
 
-DEVICE_ATTR(ssid,             0444, ssid_show,       NULL);
-DEVICE_ATTR(ddna,             0444, ddna_show,       NULL);
-DEVICE_ATTR(card_id,          0444, card_id_show,    NULL);
-DEVICE_ATTR(hw_rev,           0444, hw_rev_show,     NULL);
-DEVICE_ATTR(build,            0444, build_show,      NULL);
-DEVICE_ATTR(build_date,       0444, build_date_show, NULL);
-DEVICE_ATTR(build_time,       0444, build_time_show, NULL);
-DEVICE_ATTR(cpld_reg,         0444, cpld_reg_show,   NULL);
-DEVICE_ATTR(cpld_reconfigure, 0220, NULL,            cpld_reconfigure);
+DEVICE_ATTR_RO(ssid);
+DEVICE_ATTR_RO(ddna);
+DEVICE_ATTR_RO(card_id);
+DEVICE_ATTR_RO(hw_rev);
+DEVICE_ATTR_RO(build);
+DEVICE_ATTR_RO(build_date);
+DEVICE_ATTR_RO(build_time);
+DEVICE_ATTR_RO(cpld_reg);
+DEVICE_ATTR(cpld_reconfigure, 0220, NULL, cpld_reconfigure);
 
 static const struct attribute *kp_attr_list[] = {
 	&dev_attr_ssid.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 11/11] staging: kpc2000: declare all kp device attributes as static.
  2019-05-16 20:04 [PATCH 00/11] staging: kpc2000: another batch of fixes Jeremy Sowden
                   ` (9 preceding siblings ...)
  2019-05-16 20:04 ` [PATCH 10/11] staging: kpc2000: define read-only kp device attributes as read-only Jeremy Sowden
@ 2019-05-16 20:04 ` Jeremy Sowden
  2019-05-16 21:38 ` [PATCH v2 0/9] staging: kpc2000: another batch of fixes Jeremy Sowden
  11 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 20:04 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

The definitions are only used to populate the kp_attr_list attribute
array, so declare them as static.

Fixes the following sparse warnings:

  drivers/staging/kpc2000/kpc2000/core.c:152:1: warning: symbol 'dev_attr_ssid' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:153:1: warning: symbol 'dev_attr_ddna' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:154:1: warning: symbol 'dev_attr_card_id' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:155:1: warning: symbol 'dev_attr_hw_rev' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:156:1: warning: symbol 'dev_attr_build' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:157:1: warning: symbol 'dev_attr_build_date' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:158:1: warning: symbol 'dev_attr_build_time' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:159:1: warning: symbol 'dev_attr_cpld_reg' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:161:1: warning: symbol 'dev_attr_cpld_reconfigure' was not declared. Should it be static?

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index 55e9038117a4..05fca0581e93 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -111,15 +111,15 @@ static ssize_t cpld_reconfigure(struct device *dev,
 	return count;
 }
 
-DEVICE_ATTR_RO(ssid);
-DEVICE_ATTR_RO(ddna);
-DEVICE_ATTR_RO(card_id);
-DEVICE_ATTR_RO(hw_rev);
-DEVICE_ATTR_RO(build);
-DEVICE_ATTR_RO(build_date);
-DEVICE_ATTR_RO(build_time);
-DEVICE_ATTR_RO(cpld_reg);
-DEVICE_ATTR(cpld_reconfigure, 0220, NULL, cpld_reconfigure);
+static DEVICE_ATTR_RO(ssid);
+static DEVICE_ATTR_RO(ddna);
+static DEVICE_ATTR_RO(card_id);
+static DEVICE_ATTR_RO(hw_rev);
+static DEVICE_ATTR_RO(build);
+static DEVICE_ATTR_RO(build_date);
+static DEVICE_ATTR_RO(build_time);
+static DEVICE_ATTR_RO(cpld_reg);
+static DEVICE_ATTR(cpld_reconfigure, 0220, NULL, cpld_reconfigure);
 
 static const struct attribute *kp_attr_list[] = {
 	&dev_attr_ssid.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* RE: [PATCH 02/11] staging: kpc2000: add separate show functions for kpc_uio_class device attributes.
  2019-05-16 20:04 ` [PATCH 02/11] staging: kpc2000: add separate show functions for kpc_uio_class device attributes Jeremy Sowden
@ 2019-05-16 20:17   ` Matt Sickler
  2019-05-16 20:46     ` Jeremy Sowden
  2019-05-16 20:45   ` Greg KH
  1 sibling, 1 reply; 63+ messages in thread
From: Matt Sickler @ 2019-05-16 20:17 UTC (permalink / raw)
  To: Jeremy Sowden, Linux Driver Project Developer List; +Cc: Greg KH

>-----Original Message-----
>From: devel <driverdev-devel-bounces@linuxdriverproject.org> On Behalf Of
>Define separate simple show functions for each attribute instead of having a
>one big one containing a chain of conditionals.
>
>+static ssize_t s2c_dma_ch_show(struct device *dev,
>+                              struct device_attribute *attr, char *buf)
>+{
>+       return 0;
>+}
>+
>+static ssize_t c2s_dma_ch_show(struct device *dev,
>+                              struct device_attribute *attr, char *buf)
>+{
>+       return 0;
>+}

These two can be removed.  Technically, that would be a userspace-breaking
change, but I can guarantee that all existing userspace consumers don't actually
read that sysfs node.
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 02/11] staging: kpc2000: add separate show functions for kpc_uio_class device attributes.
  2019-05-16 20:04 ` [PATCH 02/11] staging: kpc2000: add separate show functions for kpc_uio_class device attributes Jeremy Sowden
  2019-05-16 20:17   ` Matt Sickler
@ 2019-05-16 20:45   ` Greg KH
  2019-05-16 21:06     ` Jeremy Sowden
  1 sibling, 1 reply; 63+ messages in thread
From: Greg KH @ 2019-05-16 20:45 UTC (permalink / raw)
  To: Jeremy Sowden; +Cc: Linux Driver Project Developer List

On Thu, May 16, 2019 at 09:04:02PM +0100, Jeremy Sowden wrote:
> Define separate simple show functions for each attribute instead of
> having a one big one containing a chain of conditionals.

There's nothing wrong with a change of contitionals, if you do it right
:)

> Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
> ---
>  drivers/staging/kpc2000/kpc2000/cell_probe.c | 138 ++++++++++++-------
>  1 file changed, 92 insertions(+), 46 deletions(-)
> 
> diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
> index 6a2ebdf20113..101eb23caaac 100644
> --- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
> +++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
> @@ -145,55 +145,102 @@ struct kpc_uio_device {
>      u16 core_num;
>  };
>  
> -static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
> +static ssize_t offset_show(struct device *dev, struct device_attribute *attr,
> +			   char *buf)
>  {
> -    struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> -
> -    #define ATTR_NAME_CMP(v)  (strcmp(v, attr->attr.name) == 0)
> -    if ATTR_NAME_CMP("offset"){
> -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.offset);
> -    } else if ATTR_NAME_CMP("size"){
> -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.length);
> -    } else if ATTR_NAME_CMP("type"){
> -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.type);
> -    }
> -    else if ATTR_NAME_CMP("s2c_dma"){
> -        if (kudev->cte.s2c_dma_present){
> -            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.s2c_dma_channel_num);
> -        } else {
> -            return scnprintf(buf, PAGE_SIZE, "not present\n");
> -        }
> -    } else if ATTR_NAME_CMP("c2s_dma"){
> -        if (kudev->cte.c2s_dma_present){
> -            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.c2s_dma_channel_num);
> -        } else {
> -            return scnprintf(buf, PAGE_SIZE, "not present\n");
> -        }
> -    }
> -    else if ATTR_NAME_CMP("irq_count"){
> -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_count);
> -    } else if ATTR_NAME_CMP("irq_base_num"){
> -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_base_num);
> -    } else if ATTR_NAME_CMP("core_num"){
> -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->core_num);
> -    } else {
> -        return 0;
> -    }
> -    #undef ATTR_NAME_CMP
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> +
> +	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.offset);
> +}
> +
> +static ssize_t size_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> +
> +	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.length);
>  }
>  
> +static ssize_t type_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> +
> +	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.type);
> +}
> +
> +static ssize_t s2c_dma_ch_show(struct device *dev,
> +			       struct device_attribute *attr, char *buf)
> +{
> +	return 0;
> +}
> +
> +static ssize_t c2s_dma_ch_show(struct device *dev,
> +			       struct device_attribute *attr, char *buf)
> +{
> +	return 0;
> +}
> +
> +static ssize_t s2c_dma_show(struct device *dev, struct device_attribute *attr,
> +			    char *buf)
> +{
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
>  
> -DEVICE_ATTR(offset,  0444, show_attr, NULL);
> -DEVICE_ATTR(size,    0444, show_attr, NULL);
> -DEVICE_ATTR(type,    0444, show_attr, NULL);
> -DEVICE_ATTR(s2c_dma_ch, 0444, show_attr, NULL);
> -DEVICE_ATTR(c2s_dma_ch, 0444, show_attr, NULL);
> -DEVICE_ATTR(s2c_dma, 0444, show_attr, NULL);
> -DEVICE_ATTR(c2s_dma, 0444, show_attr, NULL);
> -DEVICE_ATTR(irq_count, 0444, show_attr, NULL);
> -DEVICE_ATTR(irq_base_num, 0444, show_attr, NULL);
> -DEVICE_ATTR(core_num, 0444, show_attr, NULL);
> -struct attribute * kpc_uio_class_attrs[] = {
> +	if (!kudev->cte.s2c_dma_present)
> +		return scnprintf(buf, PAGE_SIZE, "not present\n");
> +
> +	return scnprintf(buf, PAGE_SIZE, "%u\n",
> +			 kudev->cte.s2c_dma_channel_num);
> +}
> +
> +static ssize_t c2s_dma_show(struct device *dev, struct device_attribute *attr,
> +			    char *buf)
> +{
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> +
> +	if (!kudev->cte.c2s_dma_present)
> +		return scnprintf(buf, PAGE_SIZE, "not present\n");
> +
> +	return scnprintf(buf, PAGE_SIZE, "%u\n",
> +			 kudev->cte.c2s_dma_channel_num);
> +}
> +
> +static ssize_t irq_count_show(struct device *dev, struct device_attribute *attr,
> +			      char *buf)
> +{
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> +
> +	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_count);
> +}
> +
> +static ssize_t irq_base_num_show(struct device *dev,
> +				 struct device_attribute *attr, char *buf)
> +{
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> +
> +	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_base_num);
> +}
> +
> +static ssize_t core_num_show(struct device *dev, struct device_attribute *attr,
> +			     char *buf)
> +{
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> +
> +	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->core_num);
> +}
> +
> +DEVICE_ATTR(offset,       0444, offset_show,       NULL);
> +DEVICE_ATTR(size,         0444, size_show,         NULL);
> +DEVICE_ATTR(type,         0444, type_show,         NULL);
> +DEVICE_ATTR(s2c_dma_ch,   0444, s2c_dma_ch_show,   NULL);
> +DEVICE_ATTR(c2s_dma_ch,   0444, c2s_dma_ch_show,   NULL);
> +DEVICE_ATTR(s2c_dma,      0444, s2c_dma_show,      NULL);
> +DEVICE_ATTR(c2s_dma,      0444, c2s_dma_show,      NULL);
> +DEVICE_ATTR(irq_count,    0444, irq_count_show,    NULL);
> +DEVICE_ATTR(irq_base_num, 0444, irq_base_num_show, NULL);
> +DEVICE_ATTR(core_num,     0444, core_num_show,     NULL);

If you are going to break things up like this, which is fine, you too
have to do it "right".  And by that, I mean you need to use
DEVICE_ATTR_RO().

Also, the scnprintf() nonsense can go away, that should just be a simple
sprintf().

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 02/11] staging: kpc2000: add separate show functions for kpc_uio_class device attributes.
  2019-05-16 20:17   ` Matt Sickler
@ 2019-05-16 20:46     ` Jeremy Sowden
  0 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 20:46 UTC (permalink / raw)
  To: Matt Sickler; +Cc: Greg KH, Linux Driver Project Developer List


[-- Attachment #1.1: Type: text/plain, Size: 887 bytes --]

On 2019-05-16, at 20:17:51 +0000, Matt Sickler wrote:
> >-----Original Message-----
> >From: devel <driverdev-devel-bounces@linuxdriverproject.org> On Behalf Of
> >Define separate simple show functions for each attribute instead of having a
> >one big one containing a chain of conditionals.
> >
> >+static ssize_t s2c_dma_ch_show(struct device *dev,
> >+                              struct device_attribute *attr, char *buf)
> >+{
> >+       return 0;
> >+}
> >+
> >+static ssize_t c2s_dma_ch_show(struct device *dev,
> >+                              struct device_attribute *attr, char *buf)
> >+{
> >+       return 0;
> >+}
>
> These two can be removed.  Technically, that would be a
> userspace-breaking change, but I can guarantee that all existing
> userspace consumers don't actually read that sysfs node.

Took them out in a subsequent patch.  Thanks for the confirmation.

J.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 169 bytes --]

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 02/11] staging: kpc2000: add separate show functions for kpc_uio_class device attributes.
  2019-05-16 20:45   ` Greg KH
@ 2019-05-16 21:06     ` Jeremy Sowden
  0 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 21:06 UTC (permalink / raw)
  To: Greg KH; +Cc: Linux Driver Project Developer List


[-- Attachment #1.1: Type: text/plain, Size: 6672 bytes --]

On 2019-05-16, at 22:45:33 +0200, Greg KH wrote:
> On Thu, May 16, 2019 at 09:04:02PM +0100, Jeremy Sowden wrote:
> > Define separate simple show functions for each attribute instead of
> > having a one big one containing a chain of conditionals.
>
> There's nothing wrong with a change of contitionals, if you do it right
> :)
>
> > Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
> > ---
> >  drivers/staging/kpc2000/kpc2000/cell_probe.c | 138 ++++++++++++-------
> >  1 file changed, 92 insertions(+), 46 deletions(-)
> >
> > diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
> > index 6a2ebdf20113..101eb23caaac 100644
> > --- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
> > +++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
> > @@ -145,55 +145,102 @@ struct kpc_uio_device {
> >      u16 core_num;
> >  };
> >
> > -static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
> > +static ssize_t offset_show(struct device *dev, struct device_attribute *attr,
> > +			   char *buf)
> >  {
> > -    struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> > -
> > -    #define ATTR_NAME_CMP(v)  (strcmp(v, attr->attr.name) == 0)
> > -    if ATTR_NAME_CMP("offset"){
> > -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.offset);
> > -    } else if ATTR_NAME_CMP("size"){
> > -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.length);
> > -    } else if ATTR_NAME_CMP("type"){
> > -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.type);
> > -    }
> > -    else if ATTR_NAME_CMP("s2c_dma"){
> > -        if (kudev->cte.s2c_dma_present){
> > -            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.s2c_dma_channel_num);
> > -        } else {
> > -            return scnprintf(buf, PAGE_SIZE, "not present\n");
> > -        }
> > -    } else if ATTR_NAME_CMP("c2s_dma"){
> > -        if (kudev->cte.c2s_dma_present){
> > -            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.c2s_dma_channel_num);
> > -        } else {
> > -            return scnprintf(buf, PAGE_SIZE, "not present\n");
> > -        }
> > -    }
> > -    else if ATTR_NAME_CMP("irq_count"){
> > -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_count);
> > -    } else if ATTR_NAME_CMP("irq_base_num"){
> > -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_base_num);
> > -    } else if ATTR_NAME_CMP("core_num"){
> > -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->core_num);
> > -    } else {
> > -        return 0;
> > -    }
> > -    #undef ATTR_NAME_CMP
> > +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> > +
> > +	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.offset);
> > +}
> > +
> > +static ssize_t size_show(struct device *dev, struct device_attribute *attr,
> > +			 char *buf)
> > +{
> > +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> > +
> > +	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.length);
> >  }
> >
> > +static ssize_t type_show(struct device *dev, struct device_attribute *attr,
> > +			 char *buf)
> > +{
> > +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> > +
> > +	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.type);
> > +}
> > +
> > +static ssize_t s2c_dma_ch_show(struct device *dev,
> > +			       struct device_attribute *attr, char *buf)
> > +{
> > +	return 0;
> > +}
> > +
> > +static ssize_t c2s_dma_ch_show(struct device *dev,
> > +			       struct device_attribute *attr, char *buf)
> > +{
> > +	return 0;
> > +}
> > +
> > +static ssize_t s2c_dma_show(struct device *dev, struct device_attribute *attr,
> > +			    char *buf)
> > +{
> > +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> >
> > -DEVICE_ATTR(offset,  0444, show_attr, NULL);
> > -DEVICE_ATTR(size,    0444, show_attr, NULL);
> > -DEVICE_ATTR(type,    0444, show_attr, NULL);
> > -DEVICE_ATTR(s2c_dma_ch, 0444, show_attr, NULL);
> > -DEVICE_ATTR(c2s_dma_ch, 0444, show_attr, NULL);
> > -DEVICE_ATTR(s2c_dma, 0444, show_attr, NULL);
> > -DEVICE_ATTR(c2s_dma, 0444, show_attr, NULL);
> > -DEVICE_ATTR(irq_count, 0444, show_attr, NULL);
> > -DEVICE_ATTR(irq_base_num, 0444, show_attr, NULL);
> > -DEVICE_ATTR(core_num, 0444, show_attr, NULL);
> > -struct attribute * kpc_uio_class_attrs[] = {
> > +	if (!kudev->cte.s2c_dma_present)
> > +		return scnprintf(buf, PAGE_SIZE, "not present\n");
> > +
> > +	return scnprintf(buf, PAGE_SIZE, "%u\n",
> > +			 kudev->cte.s2c_dma_channel_num);
> > +}
> > +
> > +static ssize_t c2s_dma_show(struct device *dev, struct device_attribute *attr,
> > +			    char *buf)
> > +{
> > +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> > +
> > +	if (!kudev->cte.c2s_dma_present)
> > +		return scnprintf(buf, PAGE_SIZE, "not present\n");
> > +
> > +	return scnprintf(buf, PAGE_SIZE, "%u\n",
> > +			 kudev->cte.c2s_dma_channel_num);
> > +}
> > +
> > +static ssize_t irq_count_show(struct device *dev, struct device_attribute *attr,
> > +			      char *buf)
> > +{
> > +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> > +
> > +	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_count);
> > +}
> > +
> > +static ssize_t irq_base_num_show(struct device *dev,
> > +				 struct device_attribute *attr, char *buf)
> > +{
> > +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> > +
> > +	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_base_num);
> > +}
> > +
> > +static ssize_t core_num_show(struct device *dev, struct device_attribute *attr,
> > +			     char *buf)
> > +{
> > +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> > +
> > +	return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->core_num);
> > +}
> > +
> > +DEVICE_ATTR(offset,       0444, offset_show,       NULL);
> > +DEVICE_ATTR(size,         0444, size_show,         NULL);
> > +DEVICE_ATTR(type,         0444, type_show,         NULL);
> > +DEVICE_ATTR(s2c_dma_ch,   0444, s2c_dma_ch_show,   NULL);
> > +DEVICE_ATTR(c2s_dma_ch,   0444, c2s_dma_ch_show,   NULL);
> > +DEVICE_ATTR(s2c_dma,      0444, s2c_dma_show,      NULL);
> > +DEVICE_ATTR(c2s_dma,      0444, c2s_dma_show,      NULL);
> > +DEVICE_ATTR(irq_count,    0444, irq_count_show,    NULL);
> > +DEVICE_ATTR(irq_base_num, 0444, irq_base_num_show, NULL);
> > +DEVICE_ATTR(core_num,     0444, core_num_show,     NULL);
>
> If you are going to break things up like this, which is fine, you too
> have to do it "right".  And by that, I mean you need to use
> DEVICE_ATTR_RO().

I made the change to DEVICE_ATTR_RO in a later patch.  I'll merge that
into this one.

> Also, the scnprintf() nonsense can go away, that should just be a simple
> sprintf().

Will do.

Thanks for the review.

J.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 169 bytes --]

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v2 0/9] staging: kpc2000: another batch of fixes
  2019-05-16 20:04 [PATCH 00/11] staging: kpc2000: another batch of fixes Jeremy Sowden
                   ` (10 preceding siblings ...)
  2019-05-16 20:04 ` [PATCH 11/11] staging: kpc2000: declare all kp device attributes as static Jeremy Sowden
@ 2019-05-16 21:38 ` Jeremy Sowden
  2019-05-16 21:38   ` [PATCH v2 1/9] staging: kpc2000: removed trailing white-space Jeremy Sowden
                     ` (8 more replies)
  11 siblings, 9 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 21:38 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

These apply on top of the ones I sent earlier this week, which are
currently in the staging-test branch.

There's one white-space patch, a number relating to device attributes
and one that fixes a race affecting the assignment of card numbers.

Jeremy Sowden (9):
  staging: kpc2000: removed trailing white-space.
  staging: kpc2000: add separate show functions for kpc_uio_class device
    attributes and defined them as read-only.
  staging: kpc2000: declare all kpc_uio_class device attributes as
    static.
  staging: kpc2000: removed two kpc_uio_class device attributes.
  staging: kpc2000: use atomic_t to assign card numbers.
  staging: kpc2000: simplified kp2000_device retrieval in device
    attributes call-backs.
  staging: kpc2000: formatting fixes for kp device attributes.
  staging: kpc2000: add separate show functions for readable kp device
    attributes, and defined them as read-only.
  staging: kpc2000: declare all kp device attributes as static.

 drivers/staging/kpc2000/TODO                 |   1 -
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 184 +++++++------
 drivers/staging/kpc2000/kpc2000/core.c       | 255 +++++++++++--------
 drivers/staging/kpc2000/kpc2000/fileops.c    |   2 +-
 drivers/staging/kpc2000/kpc2000/pcie.h       |  10 +-
 5 files changed, 254 insertions(+), 198 deletions(-)

Since v1:

  * merged the DEVICE_ATTR_RO patches with the ones that split up the
    show call-backs;
  * converted the show call-backs to use sprintf, instead of scnprintf.

-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v2 1/9] staging: kpc2000: removed trailing white-space.
  2019-05-16 21:38 ` [PATCH v2 0/9] staging: kpc2000: another batch of fixes Jeremy Sowden
@ 2019-05-16 21:38   ` Jeremy Sowden
  2019-05-17  7:30     ` Greg KH
  2019-05-16 21:38   ` [PATCH v2 2/9] staging: kpc2000: add separate show functions for kpc_uio_class device attributes and defined them as read-only Jeremy Sowden
                     ` (7 subsequent siblings)
  8 siblings, 1 reply; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 21:38 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Removed trailing white-space from four files.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 62 ++++++-------
 drivers/staging/kpc2000/kpc2000/core.c       | 98 ++++++++++----------
 drivers/staging/kpc2000/kpc2000/fileops.c    |  2 +-
 drivers/staging/kpc2000/kpc2000/pcie.h       | 10 +-
 4 files changed, 86 insertions(+), 86 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index bce2bf9eee04..6a2ebdf20113 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -106,24 +106,24 @@ static int probe_core_basic(unsigned int core_num, struct kp2000_device *pcard,
     };
 
     dev_dbg(&pcard->pdev->dev, "Found Basic core: type = %02d  dma = %02x / %02x  offset = 0x%x  length = 0x%x (%d regs)\n", cte.type, KPC_OLD_S2C_DMA_CH_NUM(cte), KPC_OLD_C2S_DMA_CH_NUM(cte), cte.offset, cte.length, cte.length / 8);
-    
-    
+
+
     cell.platform_data = &core_pdata;
     cell.pdata_size = sizeof(struct kpc_core_device_platdata);
     cell.num_resources = 2;
-    
+
     memset(&resources, 0, sizeof(resources));
 
     resources[0].start = cte.offset;
     resources[0].end   = cte.offset + (cte.length - 1);
     resources[0].flags = IORESOURCE_MEM;
-    
+
     resources[1].start = pcard->pdev->irq;
     resources[1].end   = pcard->pdev->irq;
     resources[1].flags = IORESOURCE_IRQ;
-    
+
     cell.resources = resources;
-    
+
     return mfd_add_devices(
         PCARD_TO_DEV(pcard),    // parent
         pcard->card_num * 100,  // id
@@ -148,7 +148,7 @@ struct kpc_uio_device {
 static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
 {
     struct kpc_uio_device *kudev = dev_get_drvdata(dev);
-    
+
     #define ATTR_NAME_CMP(v)  (strcmp(v, attr->attr.name) == 0)
     if ATTR_NAME_CMP("offset"){
         return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.offset);
@@ -228,7 +228,7 @@ irqreturn_t  kuio_handler(int irq, struct uio_info *uioinfo)
     struct kpc_uio_device *kudev = uioinfo->priv;
     if (irq != kudev->pcard->pdev->irq)
         return IRQ_NONE;
-    
+
     if (kp2000_check_uio_irq(kudev->pcard, kudev->cte.irq_base_num)){
         writeq((1 << kudev->cte.irq_base_num), kudev->pcard->sysinfo_regs_base + REG_INTERRUPT_ACTIVE); // Clear the active flag
         return IRQ_HANDLED;
@@ -242,7 +242,7 @@ int kuio_irqcontrol(struct uio_info *uioinfo, s32 irq_on)
     struct kpc_uio_device *kudev = uioinfo->priv;
     struct kp2000_device *pcard = kudev->pcard;
     u64 mask;
-    
+
     lock_card(pcard);
     mask = readq(pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
     if (irq_on){
@@ -252,7 +252,7 @@ int kuio_irqcontrol(struct uio_info *uioinfo, s32 irq_on)
     }
     writeq(mask, pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
     unlock_card(pcard);
-    
+
     return 0;
 }
 
@@ -263,18 +263,18 @@ static int probe_core_uio(unsigned int core_num, struct kp2000_device *pcard,
     int rv;
 
     dev_dbg(&pcard->pdev->dev, "Found UIO core:   type = %02d  dma = %02x / %02x  offset = 0x%x  length = 0x%x (%d regs)\n", cte.type, KPC_OLD_S2C_DMA_CH_NUM(cte), KPC_OLD_C2S_DMA_CH_NUM(cte), cte.offset, cte.length, cte.length / 8);
-    
+
     kudev = kzalloc(sizeof(struct kpc_uio_device), GFP_KERNEL);
     if (!kudev){
         dev_err(&pcard->pdev->dev, "probe_core_uio: failed to kzalloc kpc_uio_device\n");
         return -ENOMEM;
     }
-    
+
     INIT_LIST_HEAD(&kudev->list);
     kudev->pcard = pcard;
     kudev->cte = cte;
     kudev->core_num = core_num;
-    
+
     kudev->uioinfo.priv = kudev;
     kudev->uioinfo.name = name;
     kudev->uioinfo.version = "0.0";
@@ -291,7 +291,7 @@ static int probe_core_uio(unsigned int core_num, struct kp2000_device *pcard,
     kudev->uioinfo.mem[0].addr = pci_resource_start(pcard->pdev, REG_BAR) + cte.offset;
     kudev->uioinfo.mem[0].size = (cte.length + PAGE_SIZE-1) & ~(PAGE_SIZE-1); // Round up to nearest PAGE_SIZE boundary
     kudev->uioinfo.mem[0].memtype = UIO_MEM_PHYS;
-    
+
     kudev->dev = device_create(kpc_uio_class, &pcard->pdev->dev, MKDEV(0,0), kudev, "%s.%d.%d.%d", kudev->uioinfo.name, pcard->card_num, cte.type, kudev->core_num);
     if (IS_ERR(kudev->dev)) {
         dev_err(&pcard->pdev->dev, "probe_core_uio device_create failed!\n");
@@ -299,7 +299,7 @@ static int probe_core_uio(unsigned int core_num, struct kp2000_device *pcard,
         return -ENODEV;
     }
     dev_set_drvdata(kudev->dev, kudev);
-    
+
     rv = uio_register_device(kudev->dev, &kudev->uioinfo);
     if (rv){
         dev_err(&pcard->pdev->dev, "probe_core_uio failed uio_register_device: %d\n", rv);
@@ -307,9 +307,9 @@ static int probe_core_uio(unsigned int core_num, struct kp2000_device *pcard,
         kfree(kudev);
         return rv;
     }
-    
+
     list_add_tail(&kudev->list, &pcard->uio_devices_list);
-    
+
     return 0;
 }
 
@@ -320,24 +320,24 @@ static int  create_dma_engine_core(struct kp2000_device *pcard, size_t engine_re
     struct resource  resources[2];
 
     dev_dbg(&pcard->pdev->dev, "create_dma_core(pcard = [%p], engine_regs_offset = %zx, engine_num = %d)\n", pcard, engine_regs_offset, engine_num);
-    
+
     cell.platform_data = NULL;
     cell.pdata_size = 0;
     cell.name = KP_DRIVER_NAME_DMA_CONTROLLER;
     cell.num_resources = 2;
-    
+
     memset(&resources, 0, sizeof(resources));
 
     resources[0].start = engine_regs_offset;
     resources[0].end   = engine_regs_offset + (KPC_DMA_ENGINE_SIZE - 1);
     resources[0].flags = IORESOURCE_MEM;
-    
+
     resources[1].start = irq_num;
     resources[1].end   = irq_num;
     resources[1].flags = IORESOURCE_IRQ;
-    
+
     cell.resources = resources;
-    
+
     return mfd_add_devices(
         PCARD_TO_DEV(pcard),    // parent
         pcard->card_num * 100,  // id
@@ -354,7 +354,7 @@ static int  kp2000_setup_dma_controller(struct kp2000_device *pcard)
     int err;
     unsigned int i;
     u64 capabilities_reg;
-    
+
     // S2C Engines
     for (i = 0 ; i < 32 ; i++){
         capabilities_reg = readq( pcard->dma_bar_base + KPC_DMA_S2C_BASE_OFFSET + (KPC_DMA_ENGINE_SIZE * i) );
@@ -371,9 +371,9 @@ static int  kp2000_setup_dma_controller(struct kp2000_device *pcard)
             if (err) goto err_out;
         }
     }
-    
+
     return 0;
-    
+
 err_out:
     dev_err(&pcard->pdev->dev, "kp2000_setup_dma_controller: failed to add a DMA Engine: %d\n", err);
     return err;
@@ -389,12 +389,12 @@ int  kp2000_probe_cores(struct kp2000_device *pcard)
     struct core_table_entry cte;
 
     dev_dbg(&pcard->pdev->dev, "kp2000_probe_cores(pcard = %p / %d)\n", pcard, pcard->card_num);
-    
+
     err = kp2000_setup_dma_controller(pcard);
     if (err) return err;
-    
+
     INIT_LIST_HEAD(&pcard->uio_devices_list);
-    
+
     // First, iterate the core table looking for the highest CORE_ID
     for (i = 0 ; i < pcard->core_table_length ; i++){
         read_val = readq(pcard->sysinfo_regs_base + ((pcard->core_table_offset + i) * 8));
@@ -415,7 +415,7 @@ int  kp2000_probe_cores(struct kp2000_device *pcard)
         for (i = 0 ; i < pcard->core_table_length ; i++){
             read_val = readq(pcard->sysinfo_regs_base + ((pcard->core_table_offset + i) * 8));
             parse_core_table_entry(&cte, read_val, pcard->core_table_rev);
-            
+
             if (cte.type != current_type_id)
                 continue;
 
@@ -443,7 +443,7 @@ int  kp2000_probe_cores(struct kp2000_device *pcard)
             core_num++;
         }
     }
-    
+
     // Finally, instantiate a UIO device for the core_table.
     cte.type                = 0; // CORE_ID_BOARD_INFO
     cte.offset              = 0; // board info is always at the beginning
@@ -459,7 +459,7 @@ int  kp2000_probe_cores(struct kp2000_device *pcard)
         dev_err(&pcard->pdev->dev, "kp2000_probe_cores: failed to add board_info core: %d\n", err);
         goto error;
     }
-    
+
     return 0;
 
 error:
diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index 40390cdd3c8d..eb8bac62d33d 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -30,7 +30,7 @@ static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, cha
     if (!pdev)  return -ENXIO;
     pcard = pci_get_drvdata(pdev);
     if (!pcard)  return -ENXIO;
-    
+
     if (strcmp("ssid", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);  } else
     if (strcmp("ddna", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);  } else
     if (strcmp("card_id", attr->attr.name) == 0){      return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);  } else
@@ -67,11 +67,11 @@ static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *att
     if (!pdev)  return -ENXIO;
     pcard = pci_get_drvdata(pdev);
     if (!pcard)  return -ENXIO;
-    
+
     rv = kstrtol(buf, 0, &wr_val);
     if (rv < 0)  return rv;
     if (wr_val > 7)  return -EINVAL;
-    
+
     wr_val = wr_val << 8;
     wr_val |= 0x1; // Set the "Configure Go" bit
     writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
@@ -111,12 +111,12 @@ static void wait_and_read_ssid(struct kp2000_device *pcard)
 {
     u64 read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
     unsigned long timeout;
-    
+
     if (read_val & 0x8000000000000000){
         pcard->ssid = read_val;
         return;
     }
-    
+
     timeout = jiffies + (HZ * 2);
     do {
         read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
@@ -127,9 +127,9 @@ static void wait_and_read_ssid(struct kp2000_device *pcard)
         cpu_relax();
         //schedule();
     } while (time_before(jiffies, timeout));
-    
+
     dev_notice(&pcard->pdev->dev, "SSID didn't show up!\n");
-    
+
     #if 0
     // Timed out waiting for the SSID to show up, just use the DDNA instead?
     read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
@@ -143,34 +143,34 @@ static void wait_and_read_ssid(struct kp2000_device *pcard)
 static int  read_system_regs(struct kp2000_device *pcard)
 {
     u64 read_val;
-    
+
     read_val = readq(pcard->sysinfo_regs_base + REG_MAGIC_NUMBER);
     if (read_val != KP2000_MAGIC_VALUE){
         dev_err(&pcard->pdev->dev, "Invalid magic!  Got: 0x%016llx  Want: 0x%016lx\n", read_val, KP2000_MAGIC_VALUE);
         return -EILSEQ;
     }
-    
+
     read_val = readq(pcard->sysinfo_regs_base + REG_CARD_ID_AND_BUILD);
     pcard->card_id = (read_val & 0xFFFFFFFF00000000) >> 32;
     pcard->build_version = (read_val & 0x00000000FFFFFFFF) >> 0;
-    
+
     read_val = readq(pcard->sysinfo_regs_base + REG_DATE_AND_TIME_STAMPS);
     pcard->build_datestamp = (read_val & 0xFFFFFFFF00000000) >> 32;
     pcard->build_timestamp = (read_val & 0x00000000FFFFFFFF) >> 0;
-    
+
     read_val = readq(pcard->sysinfo_regs_base + REG_CORE_TABLE_OFFSET);
     pcard->core_table_length = (read_val & 0xFFFFFFFF00000000) >> 32;
     pcard->core_table_offset = (read_val & 0x00000000FFFFFFFF) >> 0;
-    
+
     wait_and_read_ssid(pcard);
-    
+
     read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_HW_ID);
     pcard->core_table_rev    = (read_val & 0x0000000000000F00) >> 8;
     pcard->hardware_revision = (read_val & 0x000000000000001F);
-    
+
     read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
     pcard->ddna = read_val;
-    
+
     dev_info(&pcard->pdev->dev, "system_regs: %08x %08x %08x %08x  %02x  %d %d  %016llx  %016llx\n",
         pcard->card_id,
         pcard->build_version,
@@ -182,12 +182,12 @@ static int  read_system_regs(struct kp2000_device *pcard)
         pcard->ssid,
         pcard->ddna
     );
-    
+
     if (pcard->core_table_rev > 1){
         dev_err(&pcard->pdev->dev, "core table entry revision is higher than we can deal with, cannot continue with this card!\n");
         return 1;
     }
-    
+
     return 0;
 }
 
@@ -209,9 +209,9 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     unsigned long dma_bar_phys_addr;
     unsigned long dma_bar_phys_len;
     u16 regval;
- 
+
     dev_dbg(&pdev->dev, "kp2000_pcie_probe(pdev = [%p], id = [%p])\n", pdev, id);
-    
+
     //{ Step 1: Allocate a struct for the pcard
     pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);
     if (NULL == pcard){
@@ -220,19 +220,19 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     }
     dev_dbg(&pdev->dev, "probe: allocated struct kp2000_device @ %p\n", pcard);
     //}
-    
+
     //{ Step 2: Initialize trivial pcard elements
     pcard->card_num = card_count;
     card_count++;
     scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
-    
+
     mutex_init(&pcard->sem);
     lock_card(pcard);
-    
+
     pcard->pdev = pdev;
     pci_set_drvdata(pdev, pcard);
     //}
-    
+
     //{ Step 3: Enable PCI device
     err = pci_enable_device(pcard->pdev);
     if (err){
@@ -240,11 +240,11 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
         goto out3;
     }
     //}
-    
+
     //{ Step 4: Setup the Register BAR
     reg_bar_phys_addr = pci_resource_start(pcard->pdev, REG_BAR);
     reg_bar_phys_len = pci_resource_len(pcard->pdev, REG_BAR);
-    
+
     pcard->regs_bar_base = ioremap_nocache(reg_bar_phys_addr, PAGE_SIZE);
     if (NULL == pcard->regs_bar_base){
         dev_err(&pcard->pdev->dev, "probe: REG_BAR could not remap memory to virtual space\n");
@@ -252,7 +252,7 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
         goto out4;
     }
     dev_dbg(&pcard->pdev->dev, "probe: REG_BAR virt hardware address start [%p]\n", pcard->regs_bar_base);
-    
+
     err = pci_request_region(pcard->pdev, REG_BAR, KP_DRIVER_NAME_KP2000);
     if (err){
         iounmap(pcard->regs_bar_base);
@@ -260,16 +260,16 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
         err = -ENODEV;
         goto out4;
     }
-    
+
     pcard->regs_base_resource.start = reg_bar_phys_addr;
     pcard->regs_base_resource.end   = reg_bar_phys_addr + reg_bar_phys_len - 1;
     pcard->regs_base_resource.flags = IORESOURCE_MEM;
     //}
-    
+
     //{ Step 5: Setup the DMA BAR
     dma_bar_phys_addr = pci_resource_start(pcard->pdev, DMA_BAR);
     dma_bar_phys_len = pci_resource_len(pcard->pdev, DMA_BAR);
-    
+
     pcard->dma_bar_base = ioremap_nocache(dma_bar_phys_addr, dma_bar_phys_len);
     if (NULL == pcard->dma_bar_base){
         dev_err(&pcard->pdev->dev, "probe: DMA_BAR could not remap memory to virtual space\n");
@@ -277,9 +277,9 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
         goto out5;
     }
     dev_dbg(&pcard->pdev->dev, "probe: DMA_BAR virt hardware address start [%p]\n", pcard->dma_bar_base);
-    
+
     pcard->dma_common_regs = pcard->dma_bar_base + KPC_DMA_COMMON_OFFSET;
-    
+
     err = pci_request_region(pcard->pdev, DMA_BAR, "kp2000_pcie");
     if (err){
         iounmap(pcard->dma_bar_base);
@@ -287,22 +287,22 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
         err = -ENODEV;
         goto out5;
     }
-    
+
     pcard->dma_base_resource.start = dma_bar_phys_addr;
     pcard->dma_base_resource.end   = dma_bar_phys_addr + dma_bar_phys_len - 1;
     pcard->dma_base_resource.flags = IORESOURCE_MEM;
     //}
-    
+
     //{ Step 6: System Regs
     pcard->sysinfo_regs_base = pcard->regs_bar_base;
     err = read_system_regs(pcard);
     if (err)
         goto out6;
-    
+
     // Disable all "user" interrupts because they're not used yet.
     writeq(0xFFFFFFFFFFFFFFFF, pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
     //}
-    
+
     //{ Step 7: Configure PCI thingies
     // let the card master PCIe
     pci_set_master(pcard->pdev);
@@ -310,19 +310,19 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     pci_read_config_word(pcard->pdev, PCI_COMMAND, &regval);
     regval |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
     pci_write_config_word(pcard->pdev, PCI_COMMAND, regval);
-    
+
     // Clear relaxed ordering bit
     pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN, 0);
-    
+
     // Set Max_Payload_Size and Max_Read_Request_Size
     regval = (0x0) << 5; // Max_Payload_Size = 128 B
     pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_PAYLOAD, regval);
     regval = (0x0) << 12; // Max_Read_Request_Size = 128 B
     pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_READRQ, regval);
-    
+
     // Enable error reporting for: Correctable Errors, Non-Fatal Errors, Fatal Errors, Unsupported Requests
     pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, 0, PCI_EXP_DEVCTL_CERE | PCI_EXP_DEVCTL_NFERE | PCI_EXP_DEVCTL_FERE | PCI_EXP_DEVCTL_URRE);
-    
+
     err = dma_set_mask(PCARD_TO_DEV(pcard), DMA_BIT_MASK(64));
     if (err){
         dev_err(&pcard->pdev->dev, "CANNOT use DMA mask %0llx\n", DMA_BIT_MASK(64));
@@ -330,19 +330,19 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     }
     dev_dbg(&pcard->pdev->dev, "Using DMA mask %0llx\n", dma_get_mask(PCARD_TO_DEV(pcard)));
     //}
-    
+
     //{ Step 8: Configure IRQs
     err = pci_enable_msi(pcard->pdev);
     if (err < 0)
         goto out8a;
-    
+
     rv = request_irq(pcard->pdev->irq, kp2000_irq_handler, IRQF_SHARED, pcard->name, pcard);
     if (rv){
         dev_err(&pcard->pdev->dev, "kp2000_pcie_probe: failed to request_irq: %d\n", rv);
         goto out8b;
     }
     //}
-    
+
     //{ Step 9: Setup sysfs attributes
     err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);
     if (err){
@@ -350,30 +350,30 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
         goto out9;
     }
     //}
-    
+
     //{ Step 10: Setup misc device
     pcard->miscdev.minor = MISC_DYNAMIC_MINOR;
     pcard->miscdev.fops = &kp2000_fops;
     pcard->miscdev.parent = &pcard->pdev->dev;
     pcard->miscdev.name = pcard->name;
-    
+
     err = misc_register(&pcard->miscdev);
     if (err){
         dev_err(&pcard->pdev->dev, "kp2000_pcie_probe: misc_register failed: %d\n", err);
         goto out10;
     }
     //}
-    
+
     //{ Step 11: Probe cores
     err = kp2000_probe_cores(pcard);
     if (err)
         goto out11;
     //}
-    
+
     //{ Step 12: Enable IRQs in HW
     SetBackEndControl(pcard->dma_common_regs, KPC_DMA_CARD_IRQ_ENABLE | KPC_DMA_CARD_USER_INTERRUPT_MODE);
     //}
-    
+
     dev_dbg(&pcard->pdev->dev, "kp2000_pcie_probe() complete!\n");
     unlock_card(pcard);
     return 0;
@@ -410,9 +410,9 @@ void  kp2000_pcie_remove(struct pci_dev *pdev)
     struct kp2000_device *pcard = pci_get_drvdata(pdev);
 
     dev_dbg(&pdev->dev, "kp2000_pcie_remove(pdev=%p)\n", pdev);
-    
+
     if (pcard == NULL)  return;
-    
+
     lock_card(pcard);
     kp2000_remove_cores(pcard);
     mfd_remove_devices(PCARD_TO_DEV(pcard));
diff --git a/drivers/staging/kpc2000/kpc2000/fileops.c b/drivers/staging/kpc2000/kpc2000/fileops.c
index b3b0b763fa1e..3e3b4800bc2c 100644
--- a/drivers/staging/kpc2000/kpc2000/fileops.c
+++ b/drivers/staging/kpc2000/kpc2000/fileops.c
@@ -88,7 +88,7 @@ long  kp2000_cdev_ioctl(struct file *filp, unsigned int ioctl_num, unsigned long
 	switch (ioctl_num){
 	case KP2000_IOCTL_GET_CPLD_REG:             return readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	case KP2000_IOCTL_GET_PCIE_ERROR_REG:       return readq(pcard->sysinfo_regs_base + REG_PCIE_ERROR_COUNT);
-    
+
 	case KP2000_IOCTL_GET_EVERYTHING: {
 		struct kp2000_regs temp;
 		int ret;
diff --git a/drivers/staging/kpc2000/kpc2000/pcie.h b/drivers/staging/kpc2000/kpc2000/pcie.h
index 893aebfd1449..8a032a5a962e 100644
--- a/drivers/staging/kpc2000/kpc2000/pcie.h
+++ b/drivers/staging/kpc2000/kpc2000/pcie.h
@@ -52,17 +52,17 @@ struct kp2000_device {
     struct pci_dev     *pdev;
     struct miscdevice   miscdev;
     char                name[16];
-    
+
     unsigned int        card_num;
     struct mutex        sem;
-    
+
     void __iomem       *sysinfo_regs_base;
     void __iomem       *regs_bar_base;
     struct resource     regs_base_resource;
     void __iomem       *dma_bar_base;
     void __iomem       *dma_common_regs;
     struct resource     dma_base_resource;
-    
+
     // "System Registers"
     u32                 card_id;
     u32                 build_version;
@@ -74,10 +74,10 @@ struct kp2000_device {
     u8                  hardware_revision;
     u64                 ssid;
     u64                 ddna;
-    
+
     // IRQ stuff
     unsigned int        irq;
-    
+
     struct list_head    uio_devices_list;
 };
 
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v2 2/9] staging: kpc2000: add separate show functions for kpc_uio_class device attributes and defined them as read-only.
  2019-05-16 21:38 ` [PATCH v2 0/9] staging: kpc2000: another batch of fixes Jeremy Sowden
  2019-05-16 21:38   ` [PATCH v2 1/9] staging: kpc2000: removed trailing white-space Jeremy Sowden
@ 2019-05-16 21:38   ` Jeremy Sowden
  2019-05-17  7:15     ` Greg KH
  2019-05-16 21:38   ` [PATCH v2 3/9] staging: kpc2000: declare all kpc_uio_class device attributes as static Jeremy Sowden
                     ` (6 subsequent siblings)
  8 siblings, 1 reply; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 21:38 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Define separate simple show functions for each attribute instead of
having a one big one containing a chain of conditionals.

Replaced scnprintf calls with sprintf since all the outputs are short
bounded strings or single integers.

All of the device attributes are read-only, so use DEVICE_ATTR_RO to
define them.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 136 ++++++++++++-------
 1 file changed, 90 insertions(+), 46 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index 6a2ebdf20113..3798f8e2e165 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -145,55 +145,100 @@ struct kpc_uio_device {
     u16 core_num;
 };
 
-static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t offset_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
 {
-    struct kpc_uio_device *kudev = dev_get_drvdata(dev);
-
-    #define ATTR_NAME_CMP(v)  (strcmp(v, attr->attr.name) == 0)
-    if ATTR_NAME_CMP("offset"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.offset);
-    } else if ATTR_NAME_CMP("size"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.length);
-    } else if ATTR_NAME_CMP("type"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.type);
-    }
-    else if ATTR_NAME_CMP("s2c_dma"){
-        if (kudev->cte.s2c_dma_present){
-            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.s2c_dma_channel_num);
-        } else {
-            return scnprintf(buf, PAGE_SIZE, "not present\n");
-        }
-    } else if ATTR_NAME_CMP("c2s_dma"){
-        if (kudev->cte.c2s_dma_present){
-            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.c2s_dma_channel_num);
-        } else {
-            return scnprintf(buf, PAGE_SIZE, "not present\n");
-        }
-    }
-    else if ATTR_NAME_CMP("irq_count"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_count);
-    } else if ATTR_NAME_CMP("irq_base_num"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_base_num);
-    } else if ATTR_NAME_CMP("core_num"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->core_num);
-    } else {
-        return 0;
-    }
-    #undef ATTR_NAME_CMP
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.offset);
+}
+
+static ssize_t size_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.length);
 }
 
+static ssize_t type_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.type);
+}
+
+static ssize_t s2c_dma_ch_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	return 0;
+}
+
+static ssize_t c2s_dma_ch_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	return 0;
+}
+
+static ssize_t s2c_dma_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
 
-DEVICE_ATTR(offset,  0444, show_attr, NULL);
-DEVICE_ATTR(size,    0444, show_attr, NULL);
-DEVICE_ATTR(type,    0444, show_attr, NULL);
-DEVICE_ATTR(s2c_dma_ch, 0444, show_attr, NULL);
-DEVICE_ATTR(c2s_dma_ch, 0444, show_attr, NULL);
-DEVICE_ATTR(s2c_dma, 0444, show_attr, NULL);
-DEVICE_ATTR(c2s_dma, 0444, show_attr, NULL);
-DEVICE_ATTR(irq_count, 0444, show_attr, NULL);
-DEVICE_ATTR(irq_base_num, 0444, show_attr, NULL);
-DEVICE_ATTR(core_num, 0444, show_attr, NULL);
-struct attribute * kpc_uio_class_attrs[] = {
+	if (!kudev->cte.s2c_dma_present)
+		return sprintf(buf, "%s", "not present\n");
+
+	return sprintf(buf, "%u\n", kudev->cte.s2c_dma_channel_num);
+}
+
+static ssize_t c2s_dma_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	if (!kudev->cte.c2s_dma_present)
+		return sprintf(buf, "%s", "not present\n");
+
+	return sprintf(buf, "%u\n", kudev->cte.c2s_dma_channel_num);
+}
+
+static ssize_t irq_count_show(struct device *dev, struct device_attribute *attr,
+			      char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.irq_count);
+}
+
+static ssize_t irq_base_num_show(struct device *dev,
+				 struct device_attribute *attr, char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.irq_base_num);
+}
+
+static ssize_t core_num_show(struct device *dev, struct device_attribute *attr,
+			     char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->core_num);
+}
+
+DEVICE_ATTR_RO(offset);
+DEVICE_ATTR_RO(size);
+DEVICE_ATTR_RO(type);
+DEVICE_ATTR_RO(s2c_dma_ch);
+DEVICE_ATTR_RO(c2s_dma_ch);
+DEVICE_ATTR_RO(s2c_dma);
+DEVICE_ATTR_RO(c2s_dma);
+DEVICE_ATTR_RO(irq_count);
+DEVICE_ATTR_RO(irq_base_num);
+DEVICE_ATTR_RO(core_num);
+
+struct attribute *kpc_uio_class_attrs[] = {
 	&dev_attr_offset.attr,
 	&dev_attr_size.attr,
 	&dev_attr_type.attr,
@@ -207,7 +252,6 @@ struct attribute * kpc_uio_class_attrs[] = {
 	NULL,
 };
 
-
 static
 int  kp2000_check_uio_irq(struct kp2000_device *pcard, u32 irq_num)
 {
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v2 3/9] staging: kpc2000: declare all kpc_uio_class device attributes as static.
  2019-05-16 21:38 ` [PATCH v2 0/9] staging: kpc2000: another batch of fixes Jeremy Sowden
  2019-05-16 21:38   ` [PATCH v2 1/9] staging: kpc2000: removed trailing white-space Jeremy Sowden
  2019-05-16 21:38   ` [PATCH v2 2/9] staging: kpc2000: add separate show functions for kpc_uio_class device attributes and defined them as read-only Jeremy Sowden
@ 2019-05-16 21:38   ` Jeremy Sowden
  2019-05-17  7:15     ` Greg KH
  2019-05-16 21:38   ` [PATCH v2 4/9] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
                     ` (5 subsequent siblings)
  8 siblings, 1 reply; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 21:38 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

The definitions are only used to populate the kpc_uio_class_attrs
attribute array, so declare them as static.

Fixes the following sparse warnings:

  drivers/staging/kpc2000/kpc2000/cell_probe.c:220:1: warning: symbol 'dev_attr_offset' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:221:1: warning: symbol 'dev_attr_size' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:222:1: warning: symbol 'dev_attr_type' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:223:1: warning: symbol 'dev_attr_s2c_dma' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:224:1: warning: symbol 'dev_attr_c2s_dma' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:225:1: warning: symbol 'dev_attr_irq_count' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:226:1: warning: symbol 'dev_attr_irq_base_num' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:227:1: warning: symbol 'dev_attr_core_num' was not declared. Should it be static?

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index 3798f8e2e165..3073b4813b7a 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -227,16 +227,16 @@ static ssize_t core_num_show(struct device *dev, struct device_attribute *attr,
 	return sprintf(buf, "%u\n", kudev->core_num);
 }
 
-DEVICE_ATTR_RO(offset);
-DEVICE_ATTR_RO(size);
-DEVICE_ATTR_RO(type);
-DEVICE_ATTR_RO(s2c_dma_ch);
-DEVICE_ATTR_RO(c2s_dma_ch);
-DEVICE_ATTR_RO(s2c_dma);
-DEVICE_ATTR_RO(c2s_dma);
-DEVICE_ATTR_RO(irq_count);
-DEVICE_ATTR_RO(irq_base_num);
-DEVICE_ATTR_RO(core_num);
+static DEVICE_ATTR_RO(offset);
+static DEVICE_ATTR_RO(size);
+static DEVICE_ATTR_RO(type);
+static DEVICE_ATTR_RO(s2c_dma_ch);
+static DEVICE_ATTR_RO(c2s_dma_ch);
+static DEVICE_ATTR_RO(s2c_dma);
+static DEVICE_ATTR_RO(c2s_dma);
+static DEVICE_ATTR_RO(irq_count);
+static DEVICE_ATTR_RO(irq_base_num);
+static DEVICE_ATTR_RO(core_num);
 
 struct attribute *kpc_uio_class_attrs[] = {
 	&dev_attr_offset.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v2 4/9] staging: kpc2000: removed two kpc_uio_class device attributes.
  2019-05-16 21:38 ` [PATCH v2 0/9] staging: kpc2000: another batch of fixes Jeremy Sowden
                     ` (2 preceding siblings ...)
  2019-05-16 21:38   ` [PATCH v2 3/9] staging: kpc2000: declare all kpc_uio_class device attributes as static Jeremy Sowden
@ 2019-05-16 21:38   ` Jeremy Sowden
  2019-05-17  7:14     ` Greg KH
  2019-05-16 21:38   ` [PATCH v2 5/9] staging: kpc2000: use atomic_t to assign card numbers Jeremy Sowden
                     ` (4 subsequent siblings)
  8 siblings, 1 reply; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 21:38 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

The show functions of two attributes output nothing and they are unused.
Removed them.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index 3073b4813b7a..c93156ba5c31 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -169,18 +169,6 @@ static ssize_t type_show(struct device *dev, struct device_attribute *attr,
 	return sprintf(buf, "%u\n", kudev->cte.type);
 }
 
-static ssize_t s2c_dma_ch_show(struct device *dev,
-			       struct device_attribute *attr, char *buf)
-{
-	return 0;
-}
-
-static ssize_t c2s_dma_ch_show(struct device *dev,
-			       struct device_attribute *attr, char *buf)
-{
-	return 0;
-}
-
 static ssize_t s2c_dma_show(struct device *dev, struct device_attribute *attr,
 			    char *buf)
 {
@@ -230,8 +218,6 @@ static ssize_t core_num_show(struct device *dev, struct device_attribute *attr,
 static DEVICE_ATTR_RO(offset);
 static DEVICE_ATTR_RO(size);
 static DEVICE_ATTR_RO(type);
-static DEVICE_ATTR_RO(s2c_dma_ch);
-static DEVICE_ATTR_RO(c2s_dma_ch);
 static DEVICE_ATTR_RO(s2c_dma);
 static DEVICE_ATTR_RO(c2s_dma);
 static DEVICE_ATTR_RO(irq_count);
@@ -242,8 +228,6 @@ struct attribute *kpc_uio_class_attrs[] = {
 	&dev_attr_offset.attr,
 	&dev_attr_size.attr,
 	&dev_attr_type.attr,
-	&dev_attr_s2c_dma_ch.attr,
-	&dev_attr_c2s_dma_ch.attr,
 	&dev_attr_s2c_dma.attr,
 	&dev_attr_c2s_dma.attr,
 	&dev_attr_irq_count.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v2 5/9] staging: kpc2000: use atomic_t to assign card numbers.
  2019-05-16 21:38 ` [PATCH v2 0/9] staging: kpc2000: another batch of fixes Jeremy Sowden
                     ` (3 preceding siblings ...)
  2019-05-16 21:38   ` [PATCH v2 4/9] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
@ 2019-05-16 21:38   ` Jeremy Sowden
  2019-05-16 22:14     ` Matt Sickler
  2019-05-16 21:38   ` [PATCH v2 6/9] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs Jeremy Sowden
                     ` (3 subsequent siblings)
  8 siblings, 1 reply; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 21:38 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Previously the next card number was assigned from a static int local
variable, which was read and later incremented.  This was not thread-
safe, so now we use an atomic_t and atomic_fetch_add instead.

Updated TODO.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/TODO           | 1 -
 drivers/staging/kpc2000/kpc2000/core.c | 7 ++++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/kpc2000/TODO b/drivers/staging/kpc2000/TODO
index 669fe5bf9637..47530e23e940 100644
--- a/drivers/staging/kpc2000/TODO
+++ b/drivers/staging/kpc2000/TODO
@@ -1,6 +1,5 @@
 - the kpc_spi driver doesn't seem to let multiple transactions (to different instances of the core) happen in parallel...
 - The kpc_i2c driver is a hot mess, it should probably be cleaned up a ton.  It functions against current hardware though.
-- pcard->card_num in kp2000_pcie_probe() is a global variable and needs atomic / locking / something better.
 - would be nice if the AIO fileops in kpc_dma could be made to work
     - probably want to add a CONFIG_ option to control compilation of the AIO functions
 - if the AIO fileops in kpc_dma start working, next would be making iov_count > 1 work too
diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index eb8bac62d33d..72130a50afd6 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0+
+#include <linux/atomic.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/pci.h>
@@ -19,6 +20,8 @@
 #include "pcie.h"
 
 
+static atomic_t next_card_num = ATOMIC_INIT(1);
+
 /*******************************************************
   * SysFS Attributes
   ******************************************************/
@@ -202,7 +205,6 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
     int err = 0;
     struct kp2000_device *pcard;
-    static int card_count = 1;
     int rv;
     unsigned long reg_bar_phys_addr;
     unsigned long reg_bar_phys_len;
@@ -222,8 +224,7 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     //}
 
     //{ Step 2: Initialize trivial pcard elements
-    pcard->card_num = card_count;
-    card_count++;
+    pcard->card_num = atomic_fetch_add(1, &next_card_num);
     scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
 
     mutex_init(&pcard->sem);
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v2 6/9] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs.
  2019-05-16 21:38 ` [PATCH v2 0/9] staging: kpc2000: another batch of fixes Jeremy Sowden
                     ` (4 preceding siblings ...)
  2019-05-16 21:38   ` [PATCH v2 5/9] staging: kpc2000: use atomic_t to assign card numbers Jeremy Sowden
@ 2019-05-16 21:38   ` Jeremy Sowden
  2019-05-16 21:38   ` [PATCH v2 7/9] staging: kpc2000: formatting fixes for kp device attributes Jeremy Sowden
                     ` (2 subsequent siblings)
  8 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 21:38 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

The call-backs used the same recipe to get the pcard from dev:

  struct pci_dev *pdev = to_pci_dev(dev);
  struct kp2000_device *pcard;

  if (!pdev) return -ENXIO;
  pcard = pci_get_drvdata(pdev);
  if (!pcard) return -ENXIO;

where to_pci_dev is a wrapper for container_of.

However, pci_set_drvdata is called before the sysfs files are created:

  int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  {
    // ...

    pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);

    // ...

    pcard->pdev = pdev;
    pci_set_drvdata(pdev, pcard);

    // ...

    err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);

Therefore, to_pci_dev and pci_get_drvdata cannot return NULL, and pcard
can be initialized directly from dev:

  struct kp2000_device *pcard = dev_get_drvdata(dev);

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 24 +++---------------------
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index 72130a50afd6..c05864cf33ce 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -27,12 +27,7 @@ static atomic_t next_card_num = ATOMIC_INIT(1);
   ******************************************************/
 static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
-    struct kp2000_device *pcard;
-
-    if (!pdev)  return -ENXIO;
-    pcard = pci_get_drvdata(pdev);
-    if (!pcard)  return -ENXIO;
+    struct kp2000_device *pcard = dev_get_drvdata(dev);
 
     if (strcmp("ssid", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);  } else
     if (strcmp("ddna", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);  } else
@@ -46,31 +41,18 @@ static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, cha
 
 static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
-	struct pci_dev *pdev = to_pci_dev(dev);
-	struct kp2000_device *pcard;
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	u64 val;
 
-	if (!pdev)
-		return -ENXIO;
-
-	pcard = pci_get_drvdata(pdev);
-	if (!pcard)
-		return -ENXIO;
-
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
 }
 static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
+    struct kp2000_device *pcard = dev_get_drvdata(dev);
     long wr_val;
-    struct kp2000_device *pcard;
     int rv;
 
-    if (!pdev)  return -ENXIO;
-    pcard = pci_get_drvdata(pdev);
-    if (!pcard)  return -ENXIO;
-
     rv = kstrtol(buf, 0, &wr_val);
     if (rv < 0)  return rv;
     if (wr_val > 7)  return -EINVAL;
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v2 7/9] staging: kpc2000: formatting fixes for kp device attributes.
  2019-05-16 21:38 ` [PATCH v2 0/9] staging: kpc2000: another batch of fixes Jeremy Sowden
                     ` (5 preceding siblings ...)
  2019-05-16 21:38   ` [PATCH v2 6/9] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs Jeremy Sowden
@ 2019-05-16 21:38   ` Jeremy Sowden
  2019-05-16 21:38   ` [PATCH v2 8/9] staging: kpc2000: add separate show functions for readable kp device attributes, and defined them as read-only Jeremy Sowden
  2019-05-16 21:38   ` [PATCH v2 9/9] staging: kpc2000: declare all kp device attributes as static Jeremy Sowden
  8 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 21:38 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Fixed indentation of cpld_reconfigure store call-back and definition of
attribute list.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 55 ++++++++++++++------------
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index c05864cf33ce..6147c47c44ab 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -47,23 +47,27 @@ static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
 }
-static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
-{
-    struct kp2000_device *pcard = dev_get_drvdata(dev);
-    long wr_val;
-    int rv;
-
-    rv = kstrtol(buf, 0, &wr_val);
-    if (rv < 0)  return rv;
-    if (wr_val > 7)  return -EINVAL;
 
-    wr_val = wr_val << 8;
-    wr_val |= 0x1; // Set the "Configure Go" bit
-    writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
-    return count;
+static ssize_t cpld_reconfigure(struct device *dev,
+				struct device_attribute *attr,
+				const char *buf, size_t count)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+	long wr_val;
+	int rv;
+
+	rv = kstrtol(buf, 0, &wr_val);
+	if (rv < 0)
+		return rv;
+	if (wr_val > 7)
+		return -EINVAL;
+
+	wr_val = wr_val << 8;
+	wr_val |= 0x1; // Set the "Configure Go" bit
+	writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
+	return count;
 }
 
-
 DEVICE_ATTR(ssid,       0444, show_attr, NULL);
 DEVICE_ATTR(ddna,       0444, show_attr, NULL);
 DEVICE_ATTR(card_id,    0444, show_attr, NULL);
@@ -74,20 +78,19 @@ DEVICE_ATTR(build_time, 0444, show_attr, NULL);
 DEVICE_ATTR(cpld_reg,   0444, show_cpld_config_reg, NULL);
 DEVICE_ATTR(cpld_reconfigure,   0220, NULL, cpld_reconfigure);
 
-static const struct attribute *  kp_attr_list[] = {
-    &dev_attr_ssid.attr,
-    &dev_attr_ddna.attr,
-    &dev_attr_card_id.attr,
-    &dev_attr_hw_rev.attr,
-    &dev_attr_build.attr,
-    &dev_attr_build_date.attr,
-    &dev_attr_build_time.attr,
-    &dev_attr_cpld_reg.attr,
-    &dev_attr_cpld_reconfigure.attr,
-    NULL,
+static const struct attribute *kp_attr_list[] = {
+	&dev_attr_ssid.attr,
+	&dev_attr_ddna.attr,
+	&dev_attr_card_id.attr,
+	&dev_attr_hw_rev.attr,
+	&dev_attr_build.attr,
+	&dev_attr_build_date.attr,
+	&dev_attr_build_time.attr,
+	&dev_attr_cpld_reg.attr,
+	&dev_attr_cpld_reconfigure.attr,
+	NULL,
 };
 
-
 /*******************************************************
   * Functions
   ******************************************************/
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v2 8/9] staging: kpc2000: add separate show functions for readable kp device attributes, and defined them as read-only.
  2019-05-16 21:38 ` [PATCH v2 0/9] staging: kpc2000: another batch of fixes Jeremy Sowden
                     ` (6 preceding siblings ...)
  2019-05-16 21:38   ` [PATCH v2 7/9] staging: kpc2000: formatting fixes for kp device attributes Jeremy Sowden
@ 2019-05-16 21:38   ` Jeremy Sowden
  2019-05-16 21:38   ` [PATCH v2 9/9] staging: kpc2000: declare all kp device attributes as static Jeremy Sowden
  8 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 21:38 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Define separate simple show functions for each attribute instead of
having a one big one containing a chain of conditionals.

Replaced calls to scnprintf with sprintf since all the outputs are
single integers.

All the readable device attributes are read-only, so use DEVICE_ATTR_RO
to define them.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 89 +++++++++++++++++++-------
 1 file changed, 66 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index 6147c47c44ab..6fa3dd6531ef 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -19,33 +19,76 @@
 #include <linux/jiffies.h>
 #include "pcie.h"
 
-
 static atomic_t next_card_num = ATOMIC_INIT(1);
 
 /*******************************************************
   * SysFS Attributes
   ******************************************************/
-static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
+
+static ssize_t ssid_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%016llx\n", pcard->ssid);
+}
+
+static ssize_t ddna_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%016llx\n", pcard->ddna);
+}
+
+static ssize_t card_id_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%08x\n", pcard->card_id);
+}
+
+static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
 {
-    struct kp2000_device *pcard = dev_get_drvdata(dev);
-
-    if (strcmp("ssid", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);  } else
-    if (strcmp("ddna", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);  } else
-    if (strcmp("card_id", attr->attr.name) == 0){      return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);  } else
-    if (strcmp("hw_rev", attr->attr.name) == 0){       return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->hardware_revision);  } else
-    if (strcmp("build", attr->attr.name) == 0){        return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_version);  } else
-    if (strcmp("build_date", attr->attr.name) == 0){   return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_datestamp);  } else
-    if (strcmp("build_time", attr->attr.name) == 0){   return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_timestamp);  } else
-    { return -ENXIO; }
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%08x\n", pcard->hardware_revision);
+}
+
+static ssize_t build_show(struct device *dev, struct device_attribute *attr,
+			  char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%08x\n", pcard->build_version);
+}
+
+static ssize_t build_date_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%08x\n", pcard->build_datestamp);
+}
+
+static ssize_t build_time_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%08x\n", pcard->build_timestamp);
 }
 
-static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t cpld_reg_show(struct device *dev, struct device_attribute *attr,
+			     char *buf)
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	u64 val;
 
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
-	return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
+	return sprintf(buf, "%016llx\n", val);
 }
 
 static ssize_t cpld_reconfigure(struct device *dev,
@@ -68,15 +111,15 @@ static ssize_t cpld_reconfigure(struct device *dev,
 	return count;
 }
 
-DEVICE_ATTR(ssid,       0444, show_attr, NULL);
-DEVICE_ATTR(ddna,       0444, show_attr, NULL);
-DEVICE_ATTR(card_id,    0444, show_attr, NULL);
-DEVICE_ATTR(hw_rev,     0444, show_attr, NULL);
-DEVICE_ATTR(build,      0444, show_attr, NULL);
-DEVICE_ATTR(build_date, 0444, show_attr, NULL);
-DEVICE_ATTR(build_time, 0444, show_attr, NULL);
-DEVICE_ATTR(cpld_reg,   0444, show_cpld_config_reg, NULL);
-DEVICE_ATTR(cpld_reconfigure,   0220, NULL, cpld_reconfigure);
+DEVICE_ATTR_RO(ssid);
+DEVICE_ATTR_RO(ddna);
+DEVICE_ATTR_RO(card_id);
+DEVICE_ATTR_RO(hw_rev);
+DEVICE_ATTR_RO(build);
+DEVICE_ATTR_RO(build_date);
+DEVICE_ATTR_RO(build_time);
+DEVICE_ATTR_RO(cpld_reg);
+DEVICE_ATTR(cpld_reconfigure, 0220, NULL, cpld_reconfigure);
 
 static const struct attribute *kp_attr_list[] = {
 	&dev_attr_ssid.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v2 9/9] staging: kpc2000: declare all kp device attributes as static.
  2019-05-16 21:38 ` [PATCH v2 0/9] staging: kpc2000: another batch of fixes Jeremy Sowden
                     ` (7 preceding siblings ...)
  2019-05-16 21:38   ` [PATCH v2 8/9] staging: kpc2000: add separate show functions for readable kp device attributes, and defined them as read-only Jeremy Sowden
@ 2019-05-16 21:38   ` Jeremy Sowden
  8 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-16 21:38 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

The definitions are only used to populate the kp_attr_list attribute
array, so declare them as static.

Fixes the following sparse warnings:

  drivers/staging/kpc2000/kpc2000/core.c:152:1: warning: symbol 'dev_attr_ssid' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:153:1: warning: symbol 'dev_attr_ddna' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:154:1: warning: symbol 'dev_attr_card_id' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:155:1: warning: symbol 'dev_attr_hw_rev' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:156:1: warning: symbol 'dev_attr_build' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:157:1: warning: symbol 'dev_attr_build_date' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:158:1: warning: symbol 'dev_attr_build_time' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:159:1: warning: symbol 'dev_attr_cpld_reg' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:161:1: warning: symbol 'dev_attr_cpld_reconfigure' was not declared. Should it be static?

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index 6fa3dd6531ef..6a06153a20ec 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -111,15 +111,15 @@ static ssize_t cpld_reconfigure(struct device *dev,
 	return count;
 }
 
-DEVICE_ATTR_RO(ssid);
-DEVICE_ATTR_RO(ddna);
-DEVICE_ATTR_RO(card_id);
-DEVICE_ATTR_RO(hw_rev);
-DEVICE_ATTR_RO(build);
-DEVICE_ATTR_RO(build_date);
-DEVICE_ATTR_RO(build_time);
-DEVICE_ATTR_RO(cpld_reg);
-DEVICE_ATTR(cpld_reconfigure, 0220, NULL, cpld_reconfigure);
+static DEVICE_ATTR_RO(ssid);
+static DEVICE_ATTR_RO(ddna);
+static DEVICE_ATTR_RO(card_id);
+static DEVICE_ATTR_RO(hw_rev);
+static DEVICE_ATTR_RO(build);
+static DEVICE_ATTR_RO(build_date);
+static DEVICE_ATTR_RO(build_time);
+static DEVICE_ATTR_RO(cpld_reg);
+static DEVICE_ATTR(cpld_reconfigure, 0220, NULL, cpld_reconfigure);
 
 static const struct attribute *kp_attr_list[] = {
 	&dev_attr_ssid.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* RE: [PATCH v2 5/9] staging: kpc2000: use atomic_t to assign card numbers.
  2019-05-16 21:38   ` [PATCH v2 5/9] staging: kpc2000: use atomic_t to assign card numbers Jeremy Sowden
@ 2019-05-16 22:14     ` Matt Sickler
  2019-05-17  7:13       ` Greg KH
  0 siblings, 1 reply; 63+ messages in thread
From: Matt Sickler @ 2019-05-16 22:14 UTC (permalink / raw)
  To: Jeremy Sowden, Linux Driver Project Developer List; +Cc: Greg KH

>-----Original Message-----
>From: devel <driverdev-devel-bounces@linuxdriverproject.org> On Behalf Of
>Previously the next card number was assigned from a static int local variable,
>which was read and later incremented.  This was not thread- safe, so now we
>use an atomic_t and atomic_fetch_add instead.

Switching to atomic_fetch_add is definitely an improvement over what that code
was doing prior, but is that the proper solution?  How do other parts of the
kernel handle giving devices unique ID numbers?

Honestly, the atomic_t solution might be "good enough".  Our PCIe devices get
removed and reprobed at least once per boot.  We do this so they boot into a
"bootloader" program so we can verify that the "production" image stored in
the on-board flash is the correct type/version.  We then tell the card to
reconfigure itself while we remove the PCIe device and then rescan the PCIe
bus for the "new" device.  That ends up increasing this card count more.
This would never be a problem in production (given that we only do this maybe
a half dozen times per boot, worst case).  Even in dev, we've never reconfigured
enough times for this counter to overflow.
That was maybe rambling a bit, just wanted to point it out in case there's a
"proper" way we should be doing this.

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v2 5/9] staging: kpc2000: use atomic_t to assign card numbers.
  2019-05-16 22:14     ` Matt Sickler
@ 2019-05-17  7:13       ` Greg KH
  0 siblings, 0 replies; 63+ messages in thread
From: Greg KH @ 2019-05-17  7:13 UTC (permalink / raw)
  To: Matt Sickler; +Cc: Linux Driver Project Developer List

On Thu, May 16, 2019 at 10:14:56PM +0000, Matt Sickler wrote:
> >-----Original Message-----
> >From: devel <driverdev-devel-bounces@linuxdriverproject.org> On Behalf Of
> >Previously the next card number was assigned from a static int local variable,
> >which was read and later incremented.  This was not thread- safe, so now we
> >use an atomic_t and atomic_fetch_add instead.
> 
> Switching to atomic_fetch_add is definitely an improvement over what that code
> was doing prior, but is that the proper solution?  How do other parts of the
> kernel handle giving devices unique ID numbers?

You use an "ida" structure.  That's the correct solution here, don't
mess with an atomic variable, that's not needed.

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v2 4/9] staging: kpc2000: removed two kpc_uio_class device attributes.
  2019-05-16 21:38   ` [PATCH v2 4/9] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
@ 2019-05-17  7:14     ` Greg KH
  0 siblings, 0 replies; 63+ messages in thread
From: Greg KH @ 2019-05-17  7:14 UTC (permalink / raw)
  To: Jeremy Sowden; +Cc: Linux Driver Project Developer List

On Thu, May 16, 2019 at 10:38:09PM +0100, Jeremy Sowden wrote:
> The show functions of two attributes output nothing and they are unused.
> Removed them.
> 
> Signed-off-by: Jeremy Sowden <jeremy@azazel.net>

You forgot a "reported-by:" tag here :(

Please add that for the next round of this patch series.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v2 2/9] staging: kpc2000: add separate show functions for kpc_uio_class device attributes and defined them as read-only.
  2019-05-16 21:38   ` [PATCH v2 2/9] staging: kpc2000: add separate show functions for kpc_uio_class device attributes and defined them as read-only Jeremy Sowden
@ 2019-05-17  7:15     ` Greg KH
  0 siblings, 0 replies; 63+ messages in thread
From: Greg KH @ 2019-05-17  7:15 UTC (permalink / raw)
  To: Jeremy Sowden; +Cc: Linux Driver Project Developer List

On Thu, May 16, 2019 at 10:38:07PM +0100, Jeremy Sowden wrote:
> Define separate simple show functions for each attribute instead of
> having a one big one containing a chain of conditionals.
> 
> Replaced scnprintf calls with sprintf since all the outputs are short
> bounded strings or single integers.
> 
> All of the device attributes are read-only, so use DEVICE_ATTR_RO to
> define them.
> 
> Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
> ---
>  drivers/staging/kpc2000/kpc2000/cell_probe.c | 136 ++++++++++++-------
>  1 file changed, 90 insertions(+), 46 deletions(-)
> 
> diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
> index 6a2ebdf20113..3798f8e2e165 100644
> --- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
> +++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
> @@ -145,55 +145,100 @@ struct kpc_uio_device {
>      u16 core_num;
>  };
>  
> -static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
> +static ssize_t offset_show(struct device *dev, struct device_attribute *attr,
> +			   char *buf)
>  {
> -    struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> -
> -    #define ATTR_NAME_CMP(v)  (strcmp(v, attr->attr.name) == 0)
> -    if ATTR_NAME_CMP("offset"){
> -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.offset);
> -    } else if ATTR_NAME_CMP("size"){
> -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.length);
> -    } else if ATTR_NAME_CMP("type"){
> -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.type);
> -    }
> -    else if ATTR_NAME_CMP("s2c_dma"){
> -        if (kudev->cte.s2c_dma_present){
> -            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.s2c_dma_channel_num);
> -        } else {
> -            return scnprintf(buf, PAGE_SIZE, "not present\n");
> -        }
> -    } else if ATTR_NAME_CMP("c2s_dma"){
> -        if (kudev->cte.c2s_dma_present){
> -            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.c2s_dma_channel_num);
> -        } else {
> -            return scnprintf(buf, PAGE_SIZE, "not present\n");
> -        }
> -    }
> -    else if ATTR_NAME_CMP("irq_count"){
> -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_count);
> -    } else if ATTR_NAME_CMP("irq_base_num"){
> -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_base_num);
> -    } else if ATTR_NAME_CMP("core_num"){
> -        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->core_num);
> -    } else {
> -        return 0;
> -    }
> -    #undef ATTR_NAME_CMP
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> +
> +	return sprintf(buf, "%u\n", kudev->cte.offset);
> +}
> +
> +static ssize_t size_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> +
> +	return sprintf(buf, "%u\n", kudev->cte.length);
>  }
>  
> +static ssize_t type_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> +
> +	return sprintf(buf, "%u\n", kudev->cte.type);
> +}
> +
> +static ssize_t s2c_dma_ch_show(struct device *dev,
> +			       struct device_attribute *attr, char *buf)
> +{
> +	return 0;
> +}
> +
> +static ssize_t c2s_dma_ch_show(struct device *dev,
> +			       struct device_attribute *attr, char *buf)
> +{
> +	return 0;
> +}
> +
> +static ssize_t s2c_dma_show(struct device *dev, struct device_attribute *attr,
> +			    char *buf)
> +{
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
>  
> -DEVICE_ATTR(offset,  0444, show_attr, NULL);
> -DEVICE_ATTR(size,    0444, show_attr, NULL);
> -DEVICE_ATTR(type,    0444, show_attr, NULL);
> -DEVICE_ATTR(s2c_dma_ch, 0444, show_attr, NULL);
> -DEVICE_ATTR(c2s_dma_ch, 0444, show_attr, NULL);
> -DEVICE_ATTR(s2c_dma, 0444, show_attr, NULL);
> -DEVICE_ATTR(c2s_dma, 0444, show_attr, NULL);
> -DEVICE_ATTR(irq_count, 0444, show_attr, NULL);
> -DEVICE_ATTR(irq_base_num, 0444, show_attr, NULL);
> -DEVICE_ATTR(core_num, 0444, show_attr, NULL);
> -struct attribute * kpc_uio_class_attrs[] = {
> +	if (!kudev->cte.s2c_dma_present)
> +		return sprintf(buf, "%s", "not present\n");
> +
> +	return sprintf(buf, "%u\n", kudev->cte.s2c_dma_channel_num);
> +}
> +
> +static ssize_t c2s_dma_show(struct device *dev, struct device_attribute *attr,
> +			    char *buf)
> +{
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> +
> +	if (!kudev->cte.c2s_dma_present)
> +		return sprintf(buf, "%s", "not present\n");
> +
> +	return sprintf(buf, "%u\n", kudev->cte.c2s_dma_channel_num);
> +}
> +
> +static ssize_t irq_count_show(struct device *dev, struct device_attribute *attr,
> +			      char *buf)
> +{
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> +
> +	return sprintf(buf, "%u\n", kudev->cte.irq_count);
> +}
> +
> +static ssize_t irq_base_num_show(struct device *dev,
> +				 struct device_attribute *attr, char *buf)
> +{
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> +
> +	return sprintf(buf, "%u\n", kudev->cte.irq_base_num);
> +}
> +
> +static ssize_t core_num_show(struct device *dev, struct device_attribute *attr,
> +			     char *buf)
> +{
> +	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
> +
> +	return sprintf(buf, "%u\n", kudev->core_num);
> +}
> +
> +DEVICE_ATTR_RO(offset);

Please put these DEVICE_ATTR_RO() lines right below the show function,
to make it a bit more obvious.  That's the normal "style" of these.

And make it static.

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v2 3/9] staging: kpc2000: declare all kpc_uio_class device attributes as static.
  2019-05-16 21:38   ` [PATCH v2 3/9] staging: kpc2000: declare all kpc_uio_class device attributes as static Jeremy Sowden
@ 2019-05-17  7:15     ` Greg KH
  0 siblings, 0 replies; 63+ messages in thread
From: Greg KH @ 2019-05-17  7:15 UTC (permalink / raw)
  To: Jeremy Sowden; +Cc: Linux Driver Project Developer List

On Thu, May 16, 2019 at 10:38:08PM +0100, Jeremy Sowden wrote:
> The definitions are only used to populate the kpc_uio_class_attrs
> attribute array, so declare them as static.
> 
> Fixes the following sparse warnings:
> 
>   drivers/staging/kpc2000/kpc2000/cell_probe.c:220:1: warning: symbol 'dev_attr_offset' was not declared. Should it be static?
>   drivers/staging/kpc2000/kpc2000/cell_probe.c:221:1: warning: symbol 'dev_attr_size' was not declared. Should it be static?
>   drivers/staging/kpc2000/kpc2000/cell_probe.c:222:1: warning: symbol 'dev_attr_type' was not declared. Should it be static?
>   drivers/staging/kpc2000/kpc2000/cell_probe.c:223:1: warning: symbol 'dev_attr_s2c_dma' was not declared. Should it be static?
>   drivers/staging/kpc2000/kpc2000/cell_probe.c:224:1: warning: symbol 'dev_attr_c2s_dma' was not declared. Should it be static?
>   drivers/staging/kpc2000/kpc2000/cell_probe.c:225:1: warning: symbol 'dev_attr_irq_count' was not declared. Should it be static?
>   drivers/staging/kpc2000/kpc2000/cell_probe.c:226:1: warning: symbol 'dev_attr_irq_base_num' was not declared. Should it be static?
>   drivers/staging/kpc2000/kpc2000/cell_probe.c:227:1: warning: symbol 'dev_attr_core_num' was not declared. Should it be static?

Ah, you did it here, nevermind...
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v2 1/9] staging: kpc2000: removed trailing white-space.
  2019-05-16 21:38   ` [PATCH v2 1/9] staging: kpc2000: removed trailing white-space Jeremy Sowden
@ 2019-05-17  7:30     ` Greg KH
  2019-05-17 11:03       ` [PATCH v3 0/6] staging: kpc2000: another batch of fixes Jeremy Sowden
  0 siblings, 1 reply; 63+ messages in thread
From: Greg KH @ 2019-05-17  7:30 UTC (permalink / raw)
  To: Jeremy Sowden; +Cc: Linux Driver Project Developer List

On Thu, May 16, 2019 at 10:38:06PM +0100, Jeremy Sowden wrote:
> Removed trailing white-space from four files.
> 
> Signed-off-by: Jeremy Sowden <jeremy@azazel.net>

I've applied, just this one patch from the series, please fix the rest
up and resend.

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v3 0/6] staging: kpc2000: another batch of fixes
  2019-05-17  7:30     ` Greg KH
@ 2019-05-17 11:03       ` Jeremy Sowden
  2019-05-17 11:03         ` [PATCH v3 1/6] staging: kpc2000: add separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                           ` (7 more replies)
  0 siblings, 8 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-17 11:03 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

These apply on top of the ones I sent earlier this week, which are
currently in the staging-test branch.

There are a number relating to device attributes and one that fixes a
race affecting the assignment of card numbers.

Jeremy Sowden (6):
  staging: kpc2000: add separate show functions for kpc_uio_class device
    attributes, defined them as read-only and declared them static.
  staging: kpc2000: removed two kpc_uio_class device attributes.
  staging: kpc2000: simplified kp2000_device retrieval in device
    attributes call-backs.
  staging: kpc2000: formatting fixes for kp device attributes.
  staging: kpc2000: add separate show functions for readable kp device
    attributes, defined them as read-only, and declared them static.
  staging: kpc2000: use IDA to assign card numbers.

 drivers/staging/kpc2000/TODO                 |   1 -
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 123 ++++++++------
 drivers/staging/kpc2000/kpc2000/core.c       | 162 +++++++++++--------
 3 files changed, 171 insertions(+), 115 deletions(-)

Since v2:

  * dropped the white-space patch since Greg has applied it;
  * added a reported-by tag to patch that drops two attributes;
  * merged the patches that declared attributes static with the ones
    that split up the show call-backs;
  * moved the attribute definitions next to their call-backs;
  * moved the patch that fixed the card-number race to the end of the
  * series;
  * use an IDA to fix the card-number race, not an atomic_t.

Since v1:

  * merged the DEVICE_ATTR_RO patches with the ones that split up the
    show call-backs;
  * converted the show call-backs to use sprintf, instead of scnprintf.

-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v3 1/6] staging: kpc2000: add separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static.
  2019-05-17 11:03       ` [PATCH v3 0/6] staging: kpc2000: another batch of fixes Jeremy Sowden
@ 2019-05-17 11:03         ` Jeremy Sowden
  2019-05-17 11:03         ` [PATCH v3 2/6] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
                           ` (6 subsequent siblings)
  7 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-17 11:03 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Define separate simple show functions for each attribute instead of
having a one big one containing a chain of conditionals.

Replaced scnprintf calls with sprintf since all the outputs are short
bounded strings or single integers.

All of the device attributes are read-only, so use DEVICE_ATTR_RO to
define them.

The definitions are only used to populate the kpc_uio_class_attrs
attribute array, so declare them as static.

Fixes the following sparse warnings:

  drivers/staging/kpc2000/kpc2000/cell_probe.c:220:1: warning: symbol 'dev_attr_offset' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:221:1: warning: symbol 'dev_attr_size' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:222:1: warning: symbol 'dev_attr_type' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:223:1: warning: symbol 'dev_attr_s2c_dma' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:224:1: warning: symbol 'dev_attr_c2s_dma' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:225:1: warning: symbol 'dev_attr_irq_count' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:226:1: warning: symbol 'dev_attr_irq_base_num' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:227:1: warning: symbol 'dev_attr_core_num' was not declared. Should it be static?

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 135 ++++++++++++-------
 1 file changed, 89 insertions(+), 46 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index 6a2ebdf20113..3339b84b8666 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -145,55 +145,99 @@ struct kpc_uio_device {
     u16 core_num;
 };
 
-static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t offset_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
 {
-    struct kpc_uio_device *kudev = dev_get_drvdata(dev);
-
-    #define ATTR_NAME_CMP(v)  (strcmp(v, attr->attr.name) == 0)
-    if ATTR_NAME_CMP("offset"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.offset);
-    } else if ATTR_NAME_CMP("size"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.length);
-    } else if ATTR_NAME_CMP("type"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.type);
-    }
-    else if ATTR_NAME_CMP("s2c_dma"){
-        if (kudev->cte.s2c_dma_present){
-            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.s2c_dma_channel_num);
-        } else {
-            return scnprintf(buf, PAGE_SIZE, "not present\n");
-        }
-    } else if ATTR_NAME_CMP("c2s_dma"){
-        if (kudev->cte.c2s_dma_present){
-            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.c2s_dma_channel_num);
-        } else {
-            return scnprintf(buf, PAGE_SIZE, "not present\n");
-        }
-    }
-    else if ATTR_NAME_CMP("irq_count"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_count);
-    } else if ATTR_NAME_CMP("irq_base_num"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_base_num);
-    } else if ATTR_NAME_CMP("core_num"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->core_num);
-    } else {
-        return 0;
-    }
-    #undef ATTR_NAME_CMP
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.offset);
+}
+static DEVICE_ATTR_RO(offset);
+
+static ssize_t size_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.length);
 }
+static DEVICE_ATTR_RO(size);
 
+static ssize_t type_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.type);
+}
+static DEVICE_ATTR_RO(type);
+
+static ssize_t s2c_dma_ch_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	return 0;
+}
+static DEVICE_ATTR_RO(s2c_dma_ch);
+
+static ssize_t c2s_dma_ch_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	return 0;
+}
+static DEVICE_ATTR_RO(c2s_dma_ch);
+
+static ssize_t s2c_dma_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
 
-DEVICE_ATTR(offset,  0444, show_attr, NULL);
-DEVICE_ATTR(size,    0444, show_attr, NULL);
-DEVICE_ATTR(type,    0444, show_attr, NULL);
-DEVICE_ATTR(s2c_dma_ch, 0444, show_attr, NULL);
-DEVICE_ATTR(c2s_dma_ch, 0444, show_attr, NULL);
-DEVICE_ATTR(s2c_dma, 0444, show_attr, NULL);
-DEVICE_ATTR(c2s_dma, 0444, show_attr, NULL);
-DEVICE_ATTR(irq_count, 0444, show_attr, NULL);
-DEVICE_ATTR(irq_base_num, 0444, show_attr, NULL);
-DEVICE_ATTR(core_num, 0444, show_attr, NULL);
-struct attribute * kpc_uio_class_attrs[] = {
+	if (!kudev->cte.s2c_dma_present)
+		return sprintf(buf, "%s", "not present\n");
+
+	return sprintf(buf, "%u\n", kudev->cte.s2c_dma_channel_num);
+}
+static DEVICE_ATTR_RO(s2c_dma);
+
+static ssize_t c2s_dma_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	if (!kudev->cte.c2s_dma_present)
+		return sprintf(buf, "%s", "not present\n");
+
+	return sprintf(buf, "%u\n", kudev->cte.c2s_dma_channel_num);
+}
+static DEVICE_ATTR_RO(c2s_dma);
+
+static ssize_t irq_count_show(struct device *dev, struct device_attribute *attr,
+			      char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.irq_count);
+}
+static DEVICE_ATTR_RO(irq_count);
+
+static ssize_t irq_base_num_show(struct device *dev,
+				 struct device_attribute *attr, char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.irq_base_num);
+}
+static DEVICE_ATTR_RO(irq_base_num);
+
+static ssize_t core_num_show(struct device *dev, struct device_attribute *attr,
+			     char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->core_num);
+}
+static DEVICE_ATTR_RO(core_num);
+
+struct attribute *kpc_uio_class_attrs[] = {
 	&dev_attr_offset.attr,
 	&dev_attr_size.attr,
 	&dev_attr_type.attr,
@@ -207,7 +251,6 @@ struct attribute * kpc_uio_class_attrs[] = {
 	NULL,
 };
 
-
 static
 int  kp2000_check_uio_irq(struct kp2000_device *pcard, u32 irq_num)
 {
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v3 2/6] staging: kpc2000: removed two kpc_uio_class device attributes.
  2019-05-17 11:03       ` [PATCH v3 0/6] staging: kpc2000: another batch of fixes Jeremy Sowden
  2019-05-17 11:03         ` [PATCH v3 1/6] staging: kpc2000: add separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
@ 2019-05-17 11:03         ` Jeremy Sowden
  2019-05-17 11:03         ` [PATCH v3 3/6] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs Jeremy Sowden
                           ` (5 subsequent siblings)
  7 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-17 11:03 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

The show functions of two attributes output nothing and they are unused.
Removed them.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Reported-by: Matt Sickler <matt.sickler@daktronics.com>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index 3339b84b8666..68d03f1d60f2 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -172,20 +172,6 @@ static ssize_t type_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(type);
 
-static ssize_t s2c_dma_ch_show(struct device *dev,
-			       struct device_attribute *attr, char *buf)
-{
-	return 0;
-}
-static DEVICE_ATTR_RO(s2c_dma_ch);
-
-static ssize_t c2s_dma_ch_show(struct device *dev,
-			       struct device_attribute *attr, char *buf)
-{
-	return 0;
-}
-static DEVICE_ATTR_RO(c2s_dma_ch);
-
 static ssize_t s2c_dma_show(struct device *dev, struct device_attribute *attr,
 			    char *buf)
 {
@@ -241,8 +227,6 @@ struct attribute *kpc_uio_class_attrs[] = {
 	&dev_attr_offset.attr,
 	&dev_attr_size.attr,
 	&dev_attr_type.attr,
-	&dev_attr_s2c_dma_ch.attr,
-	&dev_attr_c2s_dma_ch.attr,
 	&dev_attr_s2c_dma.attr,
 	&dev_attr_c2s_dma.attr,
 	&dev_attr_irq_count.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v3 3/6] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs.
  2019-05-17 11:03       ` [PATCH v3 0/6] staging: kpc2000: another batch of fixes Jeremy Sowden
  2019-05-17 11:03         ` [PATCH v3 1/6] staging: kpc2000: add separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
  2019-05-17 11:03         ` [PATCH v3 2/6] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
@ 2019-05-17 11:03         ` Jeremy Sowden
  2019-05-17 11:54           ` Greg KH
  2019-05-17 11:03         ` [PATCH v3 4/6] staging: kpc2000: formatting fixes for kp device attributes Jeremy Sowden
                           ` (4 subsequent siblings)
  7 siblings, 1 reply; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-17 11:03 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

The call-backs used the same recipe to get the pcard from dev:

  struct pci_dev *pdev = to_pci_dev(dev);
  struct kp2000_device *pcard;

  if (!pdev) return -ENXIO;
  pcard = pci_get_drvdata(pdev);
  if (!pcard) return -ENXIO;

where to_pci_dev is a wrapper for container_of.

However, pci_set_drvdata is called before the sysfs files are created:

  int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  {
    // ...

    pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);

    // ...

    pcard->pdev = pdev;
    pci_set_drvdata(pdev, pcard);

    // ...

    err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);

Therefore, to_pci_dev and pci_get_drvdata cannot return NULL, and pcard
can be initialized directly from dev:

  struct kp2000_device *pcard = dev_get_drvdata(dev);

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 24 +++---------------------
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index eb8bac62d33d..9425c4dbc2f2 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -24,12 +24,7 @@
   ******************************************************/
 static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
-    struct kp2000_device *pcard;
-
-    if (!pdev)  return -ENXIO;
-    pcard = pci_get_drvdata(pdev);
-    if (!pcard)  return -ENXIO;
+    struct kp2000_device *pcard = dev_get_drvdata(dev);
 
     if (strcmp("ssid", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);  } else
     if (strcmp("ddna", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);  } else
@@ -43,31 +38,18 @@ static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, cha
 
 static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
-	struct pci_dev *pdev = to_pci_dev(dev);
-	struct kp2000_device *pcard;
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	u64 val;
 
-	if (!pdev)
-		return -ENXIO;
-
-	pcard = pci_get_drvdata(pdev);
-	if (!pcard)
-		return -ENXIO;
-
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
 }
 static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
+    struct kp2000_device *pcard = dev_get_drvdata(dev);
     long wr_val;
-    struct kp2000_device *pcard;
     int rv;
 
-    if (!pdev)  return -ENXIO;
-    pcard = pci_get_drvdata(pdev);
-    if (!pcard)  return -ENXIO;
-
     rv = kstrtol(buf, 0, &wr_val);
     if (rv < 0)  return rv;
     if (wr_val > 7)  return -EINVAL;
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v3 4/6] staging: kpc2000: formatting fixes for kp device attributes.
  2019-05-17 11:03       ` [PATCH v3 0/6] staging: kpc2000: another batch of fixes Jeremy Sowden
                           ` (2 preceding siblings ...)
  2019-05-17 11:03         ` [PATCH v3 3/6] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs Jeremy Sowden
@ 2019-05-17 11:03         ` Jeremy Sowden
  2019-05-17 11:03         ` [PATCH v3 5/6] staging: kpc2000: add separate show functions for readable kp device attributes, defined them as read-only, and declared them static Jeremy Sowden
                           ` (3 subsequent siblings)
  7 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-17 11:03 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Fixed indentation of cpld_reconfigure store call-back and definition of
attribute list.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 55 ++++++++++++++------------
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index 9425c4dbc2f2..cbd634caeade 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -44,23 +44,27 @@ static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
 }
-static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
-{
-    struct kp2000_device *pcard = dev_get_drvdata(dev);
-    long wr_val;
-    int rv;
-
-    rv = kstrtol(buf, 0, &wr_val);
-    if (rv < 0)  return rv;
-    if (wr_val > 7)  return -EINVAL;
 
-    wr_val = wr_val << 8;
-    wr_val |= 0x1; // Set the "Configure Go" bit
-    writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
-    return count;
+static ssize_t cpld_reconfigure(struct device *dev,
+				struct device_attribute *attr,
+				const char *buf, size_t count)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+	long wr_val;
+	int rv;
+
+	rv = kstrtol(buf, 0, &wr_val);
+	if (rv < 0)
+		return rv;
+	if (wr_val > 7)
+		return -EINVAL;
+
+	wr_val = wr_val << 8;
+	wr_val |= 0x1; // Set the "Configure Go" bit
+	writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
+	return count;
 }
 
-
 DEVICE_ATTR(ssid,       0444, show_attr, NULL);
 DEVICE_ATTR(ddna,       0444, show_attr, NULL);
 DEVICE_ATTR(card_id,    0444, show_attr, NULL);
@@ -71,20 +75,19 @@ DEVICE_ATTR(build_time, 0444, show_attr, NULL);
 DEVICE_ATTR(cpld_reg,   0444, show_cpld_config_reg, NULL);
 DEVICE_ATTR(cpld_reconfigure,   0220, NULL, cpld_reconfigure);
 
-static const struct attribute *  kp_attr_list[] = {
-    &dev_attr_ssid.attr,
-    &dev_attr_ddna.attr,
-    &dev_attr_card_id.attr,
-    &dev_attr_hw_rev.attr,
-    &dev_attr_build.attr,
-    &dev_attr_build_date.attr,
-    &dev_attr_build_time.attr,
-    &dev_attr_cpld_reg.attr,
-    &dev_attr_cpld_reconfigure.attr,
-    NULL,
+static const struct attribute *kp_attr_list[] = {
+	&dev_attr_ssid.attr,
+	&dev_attr_ddna.attr,
+	&dev_attr_card_id.attr,
+	&dev_attr_hw_rev.attr,
+	&dev_attr_build.attr,
+	&dev_attr_build_date.attr,
+	&dev_attr_build_time.attr,
+	&dev_attr_cpld_reg.attr,
+	&dev_attr_cpld_reconfigure.attr,
+	NULL,
 };
 
-
 /*******************************************************
   * Functions
   ******************************************************/
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v3 5/6] staging: kpc2000: add separate show functions for readable kp device attributes, defined them as read-only, and declared them static.
  2019-05-17 11:03       ` [PATCH v3 0/6] staging: kpc2000: another batch of fixes Jeremy Sowden
                           ` (3 preceding siblings ...)
  2019-05-17 11:03         ` [PATCH v3 4/6] staging: kpc2000: formatting fixes for kp device attributes Jeremy Sowden
@ 2019-05-17 11:03         ` Jeremy Sowden
  2019-05-17 11:03         ` [PATCH v3 6/6] staging: kpc2000: use IDA to assign card numbers Jeremy Sowden
                           ` (2 subsequent siblings)
  7 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-17 11:03 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Define separate simple show functions for each attribute instead of
having a one big one containing a chain of conditionals.

Replaced calls to scnprintf with sprintf since all the outputs are
single integers.

All the readable device attributes are read-only, so use DEVICE_ATTR_RO
to define them.

The definitions are only used to populate the kp_attr_list attribute
array, so declare them as static.

Fixes the following sparse warnings:

  drivers/staging/kpc2000/kpc2000/core.c:152:1: warning: symbol 'dev_attr_ssid' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:153:1: warning: symbol 'dev_attr_ddna' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:154:1: warning: symbol 'dev_attr_card_id' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:155:1: warning: symbol 'dev_attr_hw_rev' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:156:1: warning: symbol 'dev_attr_build' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:157:1: warning: symbol 'dev_attr_build_date' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:158:1: warning: symbol 'dev_attr_build_time' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:159:1: warning: symbol 'dev_attr_cpld_reg' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:161:1: warning: symbol 'dev_attr_cpld_reconfigure' was not declared. Should it be static?

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 89 +++++++++++++++++++-------
 1 file changed, 66 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index cbd634caeade..80141514f7d1 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -22,28 +22,80 @@
 /*******************************************************
   * SysFS Attributes
   ******************************************************/
-static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
+
+static ssize_t ssid_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%016llx\n", pcard->ssid);
+}
+static DEVICE_ATTR_RO(ssid);
+
+static ssize_t ddna_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%016llx\n", pcard->ddna);
+}
+static DEVICE_ATTR_RO(ddna);
+
+static ssize_t card_id_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%08x\n", pcard->card_id);
+}
+static DEVICE_ATTR_RO(card_id);
+
+static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%08x\n", pcard->hardware_revision);
+}
+static DEVICE_ATTR_RO(hw_rev);
+
+static ssize_t build_show(struct device *dev, struct device_attribute *attr,
+			  char *buf)
 {
-    struct kp2000_device *pcard = dev_get_drvdata(dev);
-
-    if (strcmp("ssid", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);  } else
-    if (strcmp("ddna", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);  } else
-    if (strcmp("card_id", attr->attr.name) == 0){      return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);  } else
-    if (strcmp("hw_rev", attr->attr.name) == 0){       return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->hardware_revision);  } else
-    if (strcmp("build", attr->attr.name) == 0){        return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_version);  } else
-    if (strcmp("build_date", attr->attr.name) == 0){   return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_datestamp);  } else
-    if (strcmp("build_time", attr->attr.name) == 0){   return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_timestamp);  } else
-    { return -ENXIO; }
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%08x\n", pcard->build_version);
 }
+static DEVICE_ATTR_RO(build);
 
-static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t build_date_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%08x\n", pcard->build_datestamp);
+}
+static DEVICE_ATTR_RO(build_date);
+
+static ssize_t build_time_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%08x\n", pcard->build_timestamp);
+}
+static DEVICE_ATTR_RO(build_time);
+
+static ssize_t cpld_reg_show(struct device *dev, struct device_attribute *attr,
+			     char *buf)
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	u64 val;
 
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
-	return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
+	return sprintf(buf, "%016llx\n", val);
 }
+static DEVICE_ATTR_RO(cpld_reg);
 
 static ssize_t cpld_reconfigure(struct device *dev,
 				struct device_attribute *attr,
@@ -64,16 +116,7 @@ static ssize_t cpld_reconfigure(struct device *dev,
 	writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	return count;
 }
-
-DEVICE_ATTR(ssid,       0444, show_attr, NULL);
-DEVICE_ATTR(ddna,       0444, show_attr, NULL);
-DEVICE_ATTR(card_id,    0444, show_attr, NULL);
-DEVICE_ATTR(hw_rev,     0444, show_attr, NULL);
-DEVICE_ATTR(build,      0444, show_attr, NULL);
-DEVICE_ATTR(build_date, 0444, show_attr, NULL);
-DEVICE_ATTR(build_time, 0444, show_attr, NULL);
-DEVICE_ATTR(cpld_reg,   0444, show_cpld_config_reg, NULL);
-DEVICE_ATTR(cpld_reconfigure,   0220, NULL, cpld_reconfigure);
+static DEVICE_ATTR(cpld_reconfigure, 0220, NULL, cpld_reconfigure);
 
 static const struct attribute *kp_attr_list[] = {
 	&dev_attr_ssid.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v3 6/6] staging: kpc2000: use IDA to assign card numbers.
  2019-05-17 11:03       ` [PATCH v3 0/6] staging: kpc2000: another batch of fixes Jeremy Sowden
                           ` (4 preceding siblings ...)
  2019-05-17 11:03         ` [PATCH v3 5/6] staging: kpc2000: add separate show functions for readable kp device attributes, defined them as read-only, and declared them static Jeremy Sowden
@ 2019-05-17 11:03         ` Jeremy Sowden
  2019-05-17 11:50           ` Greg KH
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
  2019-05-20 20:03         ` git-send-email cock-up [Was: Re: [PATCH v3 0/6] staging: kpc2000: another batch of fixes] Jeremy Sowden
  7 siblings, 1 reply; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-17 11:03 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Previously the next card number was assigned from a static int local
variable, which was read and later incremented.  This was not thread-
safe, so now we use an IDA instead.

Updated TODO.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/TODO           |  1 -
 drivers/staging/kpc2000/kpc2000/core.c | 15 ++++++++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/kpc2000/TODO b/drivers/staging/kpc2000/TODO
index 669fe5bf9637..47530e23e940 100644
--- a/drivers/staging/kpc2000/TODO
+++ b/drivers/staging/kpc2000/TODO
@@ -1,6 +1,5 @@
 - the kpc_spi driver doesn't seem to let multiple transactions (to different instances of the core) happen in parallel...
 - The kpc_i2c driver is a hot mess, it should probably be cleaned up a ton.  It functions against current hardware though.
-- pcard->card_num in kp2000_pcie_probe() is a global variable and needs atomic / locking / something better.
 - would be nice if the AIO fileops in kpc_dma could be made to work
     - probably want to add a CONFIG_ option to control compilation of the AIO functions
 - if the AIO fileops in kpc_dma start working, next would be making iov_count > 1 work too
diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index 80141514f7d1..3a90cdad3eb4 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0+
+#include <linux/idr.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/pci.h>
@@ -18,6 +19,7 @@
 #include <linux/jiffies.h>
 #include "pcie.h"
 
+static DEFINE_IDA(card_num_ida);
 
 /*******************************************************
   * SysFS Attributes
@@ -230,7 +232,6 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
     int err = 0;
     struct kp2000_device *pcard;
-    static int card_count = 1;
     int rv;
     unsigned long reg_bar_phys_addr;
     unsigned long reg_bar_phys_len;
@@ -250,8 +251,13 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     //}
 
     //{ Step 2: Initialize trivial pcard elements
-    pcard->card_num = card_count;
-    card_count++;
+    rv = ida_simple_get(&card_num_ida, 1, INT_MAX, GFP_KERNEL);
+    if (rv < 0) {
+	err = rv;
+	dev_err(&pdev->dev, "probe: failed to get card number (%d)\n", err);
+	goto out2;
+    }
+    pcard->card_num = rv;
     scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
 
     mutex_init(&pcard->sem);
@@ -428,6 +434,8 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     pci_disable_device(pcard->pdev);
   out3:
     unlock_card(pcard);
+    ida_simple_remove(&card_num_ida, pcard->card_num);
+  out2:
     kfree(pcard);
     return err;
 }
@@ -461,5 +469,6 @@ void  kp2000_pcie_remove(struct pci_dev *pdev)
     pci_disable_device(pcard->pdev);
     pci_set_drvdata(pdev, NULL);
     unlock_card(pcard);
+    ida_simple_remove(&card_num_ida, pcard->card_num);
     kfree(pcard);
 }
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 6/6] staging: kpc2000: use IDA to assign card numbers.
  2019-05-17 11:03         ` [PATCH v3 6/6] staging: kpc2000: use IDA to assign card numbers Jeremy Sowden
@ 2019-05-17 11:50           ` Greg KH
  2019-05-17 12:19             ` Jeremy Sowden
  0 siblings, 1 reply; 63+ messages in thread
From: Greg KH @ 2019-05-17 11:50 UTC (permalink / raw)
  To: Jeremy Sowden; +Cc: Linux Driver Project Developer List

On Fri, May 17, 2019 at 12:03:15PM +0100, Jeremy Sowden wrote:
> Previously the next card number was assigned from a static int local
> variable, which was read and later incremented.  This was not thread-
> safe, so now we use an IDA instead.

An ida is not thread safe either.

But, you are onlyu touching this from the pci probe/release functions,
which are guaranteed to never race for a specific driver, so you could
use a static int if you were just worried about the race.

So the changelog really isn't correct here :(

> 
> Updated TODO.
> 
> Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
> ---
>  drivers/staging/kpc2000/TODO           |  1 -
>  drivers/staging/kpc2000/kpc2000/core.c | 15 ++++++++++++---
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/kpc2000/TODO b/drivers/staging/kpc2000/TODO
> index 669fe5bf9637..47530e23e940 100644
> --- a/drivers/staging/kpc2000/TODO
> +++ b/drivers/staging/kpc2000/TODO
> @@ -1,6 +1,5 @@
>  - the kpc_spi driver doesn't seem to let multiple transactions (to different instances of the core) happen in parallel...
>  - The kpc_i2c driver is a hot mess, it should probably be cleaned up a ton.  It functions against current hardware though.
> -- pcard->card_num in kp2000_pcie_probe() is a global variable and needs atomic / locking / something better.
>  - would be nice if the AIO fileops in kpc_dma could be made to work
>      - probably want to add a CONFIG_ option to control compilation of the AIO functions
>  - if the AIO fileops in kpc_dma start working, next would be making iov_count > 1 work too
> diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
> index 80141514f7d1..3a90cdad3eb4 100644
> --- a/drivers/staging/kpc2000/kpc2000/core.c
> +++ b/drivers/staging/kpc2000/kpc2000/core.c
> @@ -1,4 +1,5 @@
>  // SPDX-License-Identifier: GPL-2.0+
> +#include <linux/idr.h>
>  #include <linux/init.h>
>  #include <linux/module.h>
>  #include <linux/pci.h>
> @@ -18,6 +19,7 @@
>  #include <linux/jiffies.h>
>  #include "pcie.h"
>  
> +static DEFINE_IDA(card_num_ida);
>  
>  /*******************************************************
>    * SysFS Attributes
> @@ -230,7 +232,6 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>  {
>      int err = 0;
>      struct kp2000_device *pcard;
> -    static int card_count = 1;
>      int rv;
>      unsigned long reg_bar_phys_addr;
>      unsigned long reg_bar_phys_len;
> @@ -250,8 +251,13 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>      //}
>  
>      //{ Step 2: Initialize trivial pcard elements
> -    pcard->card_num = card_count;
> -    card_count++;
> +    rv = ida_simple_get(&card_num_ida, 1, INT_MAX, GFP_KERNEL);
> +    if (rv < 0) {
> +	err = rv;
> +	dev_err(&pdev->dev, "probe: failed to get card number (%d)\n", err);
> +	goto out2;
> +    }
> +    pcard->card_num = rv;

When writing new code, you could use the correct coding style please.

Why is 'rv' even needed here?  Just use err.

>      scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
>  
>      mutex_init(&pcard->sem);
> @@ -428,6 +434,8 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>      pci_disable_device(pcard->pdev);
>    out3:
>      unlock_card(pcard);
> +    ida_simple_remove(&card_num_ida, pcard->card_num);
> +  out2:
>      kfree(pcard);
>      return err;
>  }
> @@ -461,5 +469,6 @@ void  kp2000_pcie_remove(struct pci_dev *pdev)
>      pci_disable_device(pcard->pdev);
>      pci_set_drvdata(pdev, NULL);
>      unlock_card(pcard);
> +    ida_simple_remove(&card_num_ida, pcard->card_num);
>      kfree(pcard);
>  }

You forgot to call ida_destroy() when the module is unloaded :(

Yeah, it's not obvious, and is supposed to be fixed up soon, but for now
you still need to do that.

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/6] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs.
  2019-05-17 11:03         ` [PATCH v3 3/6] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs Jeremy Sowden
@ 2019-05-17 11:54           ` Greg KH
  2019-05-17 12:18             ` Jeremy Sowden
  2019-05-21 11:23             ` Dan Carpenter
  0 siblings, 2 replies; 63+ messages in thread
From: Greg KH @ 2019-05-17 11:54 UTC (permalink / raw)
  To: Jeremy Sowden; +Cc: Linux Driver Project Developer List

On Fri, May 17, 2019 at 12:03:12PM +0100, Jeremy Sowden wrote:
> The call-backs used the same recipe to get the pcard from dev:
> 
>   struct pci_dev *pdev = to_pci_dev(dev);
>   struct kp2000_device *pcard;
> 
>   if (!pdev) return -ENXIO;
>   pcard = pci_get_drvdata(pdev);
>   if (!pcard) return -ENXIO;
> 
> where to_pci_dev is a wrapper for container_of.
> 
> However, pci_set_drvdata is called before the sysfs files are created:
> 
>   int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>   {
>     // ...
> 
>     pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);
> 
>     // ...
> 
>     pcard->pdev = pdev;
>     pci_set_drvdata(pdev, pcard);
> 
>     // ...
> 
>     err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);
> 
> Therefore, to_pci_dev and pci_get_drvdata cannot return NULL, and pcard
> can be initialized directly from dev:
> 
>   struct kp2000_device *pcard = dev_get_drvdata(dev);
> 
> Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
> ---
>  drivers/staging/kpc2000/kpc2000/core.c | 24 +++---------------------
>  1 file changed, 3 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
> index eb8bac62d33d..9425c4dbc2f2 100644
> --- a/drivers/staging/kpc2000/kpc2000/core.c
> +++ b/drivers/staging/kpc2000/kpc2000/core.c
> @@ -24,12 +24,7 @@
>    ******************************************************/
>  static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
>  {
> -    struct pci_dev *pdev = to_pci_dev(dev);
> -    struct kp2000_device *pcard;
> -
> -    if (!pdev)  return -ENXIO;
> -    pcard = pci_get_drvdata(pdev);
> -    if (!pcard)  return -ENXIO;
> +    struct kp2000_device *pcard = dev_get_drvdata(dev);

Wait, dev_get_drvdata() is not returning you the same pointer that
pci_get_drvdata() does.  So I think this is now broken :(

What this should look like is this:
	struct pci_dev *pdev = to_pci_dev(dev);
	struct kp200_device *pcard = pci_get_drvdata(pdev);

	if (!pcard)
		return -ENODEV;

that is IF the driver really is setting the pci dev data to NULL when
the device is removed from the driver.  Is it?

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/6] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs.
  2019-05-17 11:54           ` Greg KH
@ 2019-05-17 12:18             ` Jeremy Sowden
  2019-05-21 11:23             ` Dan Carpenter
  1 sibling, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-17 12:18 UTC (permalink / raw)
  To: Greg KH; +Cc: Linux Driver Project Developer List


[-- Attachment #1.1: Type: text/plain, Size: 3280 bytes --]

On 2019-05-17, at 13:54:51 +0200, Greg KH wrote:
> On Fri, May 17, 2019 at 12:03:12PM +0100, Jeremy Sowden wrote:
> > The call-backs used the same recipe to get the pcard from dev:
> >
> >   struct pci_dev *pdev = to_pci_dev(dev);
> >   struct kp2000_device *pcard;
> >
> >   if (!pdev) return -ENXIO;
> >   pcard = pci_get_drvdata(pdev);
> >   if (!pcard) return -ENXIO;
> >
> > where to_pci_dev is a wrapper for container_of.
> >
> > However, pci_set_drvdata is called before the sysfs files are
> > created:
> >
> >   int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> >   {
> >     // ...
> >
> >     pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);
> >
> >     // ...
> >
> >     pcard->pdev = pdev;
> >     pci_set_drvdata(pdev, pcard);
> >
> >     // ...
> >
> >     err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);
> >
> > Therefore, to_pci_dev and pci_get_drvdata cannot return NULL, and
> > pcard can be initialized directly from dev:
> >
> >   struct kp2000_device *pcard = dev_get_drvdata(dev);
> >
> > Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
> > ---
> >  drivers/staging/kpc2000/kpc2000/core.c | 24 +++---------------------
> >  1 file changed, 3 insertions(+), 21 deletions(-)
> >
> > diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
> > index eb8bac62d33d..9425c4dbc2f2 100644
> > --- a/drivers/staging/kpc2000/kpc2000/core.c
> > +++ b/drivers/staging/kpc2000/kpc2000/core.c
> > @@ -24,12 +24,7 @@
> >    ******************************************************/
> >  static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
> >  {
> > -    struct pci_dev *pdev = to_pci_dev(dev);
> > -    struct kp2000_device *pcard;
> > -
> > -    if (!pdev)  return -ENXIO;
> > -    pcard = pci_get_drvdata(pdev);
> > -    if (!pcard)  return -ENXIO;
> > +    struct kp2000_device *pcard = dev_get_drvdata(dev);
>
> Wait, dev_get_drvdata() is not returning you the same pointer that
> pci_get_drvdata() does.  So I think this is now broken :(

I'm confused.  Perhaps I'm looking at the wrong code.

Here are pci_get_drvdata:

  static inline void *pci_get_drvdata(struct pci_dev *pdev)
  {
          return dev_get_drvdata(&pdev->dev);
  }

and dev_get_drvdata:

  static inline void *dev_get_drvdata(const struct device *dev)
  {
          return dev->driver_data;
  }

Starting withing with dev and using to_pci_dev, we have:

  pci_get_drvdata(to_pci_dev(dev))

which is the same as:

  dev_get_drvdata(&(to_pci_dev(dev)->dev)

which is the same as:

  dev_get_drvdata(dev)

isn't it?

> What this should look like is this:
> 	struct pci_dev *pdev = to_pci_dev(dev);
> 	struct kp200_device *pcard = pci_get_drvdata(pdev);
>
> 	if (!pcard)
> 		return -ENODEV;
>
> that is IF the driver really is setting the pci dev data to NULL when
> the device is removed from the driver.  Is it?

It sets it to NULL after removing the sysfs files and disabling the
device:

    lock_card(pcard);
    // ...
    sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
    // ...
    pci_disable_device(pcard->pdev);
    pci_set_drvdata(pdev, NULL);
    unlock_card(pcard);
    kfree(pcard);

Can the show functions get called after pci_set_drvdata is called?

J.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 169 bytes --]

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 6/6] staging: kpc2000: use IDA to assign card numbers.
  2019-05-17 11:50           ` Greg KH
@ 2019-05-17 12:19             ` Jeremy Sowden
  0 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-17 12:19 UTC (permalink / raw)
  To: Greg KH; +Cc: Linux Driver Project Developer List


[-- Attachment #1.1: Type: text/plain, Size: 4284 bytes --]

On 2019-05-17, at 13:50:13 +0200, Greg KH wrote:
> On Fri, May 17, 2019 at 12:03:15PM +0100, Jeremy Sowden wrote:
> > Previously the next card number was assigned from a static int local
> > variable, which was read and later incremented.  This was not
> > thread- safe, so now we use an IDA instead.
>
> An ida is not thread safe either.

Most of the IDR's I looked at were protected by locks, but none of the
IDA's ...

> But, you are onlyu touching this from the pci probe/release functions,
> which are guaranteed to never race for a specific driver, so you could
> use a static int if you were just worried about the race.

... guessing this is why.

> So the changelog really isn't correct here :(

Will fix.

> > Updated TODO.
> >
> > Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
> > ---
> >  drivers/staging/kpc2000/TODO           |  1 -
> >  drivers/staging/kpc2000/kpc2000/core.c | 15 ++++++++++++---
> >  2 files changed, 12 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/staging/kpc2000/TODO b/drivers/staging/kpc2000/TODO
> > index 669fe5bf9637..47530e23e940 100644
> > --- a/drivers/staging/kpc2000/TODO
> > +++ b/drivers/staging/kpc2000/TODO
> > @@ -1,6 +1,5 @@
> >  - the kpc_spi driver doesn't seem to let multiple transactions (to different instances of the core) happen in parallel...
> >  - The kpc_i2c driver is a hot mess, it should probably be cleaned up a ton.  It functions against current hardware though.
> > -- pcard->card_num in kp2000_pcie_probe() is a global variable and needs atomic / locking / something better.
> >  - would be nice if the AIO fileops in kpc_dma could be made to work
> >      - probably want to add a CONFIG_ option to control compilation of the AIO functions
> >  - if the AIO fileops in kpc_dma start working, next would be making iov_count > 1 work too
> > diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
> > index 80141514f7d1..3a90cdad3eb4 100644
> > --- a/drivers/staging/kpc2000/kpc2000/core.c
> > +++ b/drivers/staging/kpc2000/kpc2000/core.c
> > @@ -1,4 +1,5 @@
> >  // SPDX-License-Identifier: GPL-2.0+
> > +#include <linux/idr.h>
> >  #include <linux/init.h>
> >  #include <linux/module.h>
> >  #include <linux/pci.h>
> > @@ -18,6 +19,7 @@
> >  #include <linux/jiffies.h>
> >  #include "pcie.h"
> >
> > +static DEFINE_IDA(card_num_ida);
> >
> >  /*******************************************************
> >    * SysFS Attributes
> > @@ -230,7 +232,6 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> >  {
> >      int err = 0;
> >      struct kp2000_device *pcard;
> > -    static int card_count = 1;
> >      int rv;
> >      unsigned long reg_bar_phys_addr;
> >      unsigned long reg_bar_phys_len;
> > @@ -250,8 +251,13 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> >      //}
> >
> >      //{ Step 2: Initialize trivial pcard elements
> > -    pcard->card_num = card_count;
> > -    card_count++;
> > +    rv = ida_simple_get(&card_num_ida, 1, INT_MAX, GFP_KERNEL);
> > +    if (rv < 0) {
> > +	err = rv;
> > +	dev_err(&pdev->dev, "probe: failed to get card number (%d)\n", err);
> > +	goto out2;
> > +    }
> > +    pcard->card_num = rv;
>
> When writing new code, you could use the correct coding style please.
>
> Why is 'rv' even needed here?  Just use err.

Will fix.

> >      scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
> >
> >      mutex_init(&pcard->sem);
> > @@ -428,6 +434,8 @@ int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> >      pci_disable_device(pcard->pdev);
> >    out3:
> >      unlock_card(pcard);
> > +    ida_simple_remove(&card_num_ida, pcard->card_num);
> > +  out2:
> >      kfree(pcard);
> >      return err;
> >  }
> > @@ -461,5 +469,6 @@ void  kp2000_pcie_remove(struct pci_dev *pdev)
> >      pci_disable_device(pcard->pdev);
> >      pci_set_drvdata(pdev, NULL);
> >      unlock_card(pcard);
> > +    ida_simple_remove(&card_num_ida, pcard->card_num);
> >      kfree(pcard);
> >  }
>
> You forgot to call ida_destroy() when the module is unloaded :(
>
> Yeah, it's not obvious, and is supposed to be fixed up soon, but for now
> you still need to do that.

Nuts.  Missed it.  Will fix.

Thanks for the review.

J.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 169 bytes --]

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static.
  2019-05-17 11:03       ` [PATCH v3 0/6] staging: kpc2000: another batch of fixes Jeremy Sowden
                           ` (5 preceding siblings ...)
  2019-05-17 11:03         ` [PATCH v3 6/6] staging: kpc2000: use IDA to assign card numbers Jeremy Sowden
@ 2019-05-20 19:52         ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH 2/8] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
                             ` (15 more replies)
  2019-05-20 20:03         ` git-send-email cock-up [Was: Re: [PATCH v3 0/6] staging: kpc2000: another batch of fixes] Jeremy Sowden
  7 siblings, 16 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Defined separate simple show functions for each attribute instead of
having a one big one containing a chain of conditionals.

Replaced scnprintf calls with sprintf since all the outputs are short
bounded strings or single integers.

All of the device attributes are read-only, so used DEVICE_ATTR_RO to
define them.

The definitions are only used to populate the kpc_uio_class_attrs
attribute array, so declared them as static.

Fixes the following sparse warnings:

  drivers/staging/kpc2000/kpc2000/cell_probe.c:220:1: warning: symbol 'dev_attr_offset' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:221:1: warning: symbol 'dev_attr_size' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:222:1: warning: symbol 'dev_attr_type' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:223:1: warning: symbol 'dev_attr_s2c_dma' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:224:1: warning: symbol 'dev_attr_c2s_dma' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:225:1: warning: symbol 'dev_attr_irq_count' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:226:1: warning: symbol 'dev_attr_irq_base_num' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:227:1: warning: symbol 'dev_attr_core_num' was not declared. Should it be static?

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 135 ++++++++++++-------
 1 file changed, 89 insertions(+), 46 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index 6a2ebdf20113..3339b84b8666 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -145,55 +145,99 @@ struct kpc_uio_device {
     u16 core_num;
 };
 
-static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t offset_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
 {
-    struct kpc_uio_device *kudev = dev_get_drvdata(dev);
-
-    #define ATTR_NAME_CMP(v)  (strcmp(v, attr->attr.name) == 0)
-    if ATTR_NAME_CMP("offset"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.offset);
-    } else if ATTR_NAME_CMP("size"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.length);
-    } else if ATTR_NAME_CMP("type"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.type);
-    }
-    else if ATTR_NAME_CMP("s2c_dma"){
-        if (kudev->cte.s2c_dma_present){
-            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.s2c_dma_channel_num);
-        } else {
-            return scnprintf(buf, PAGE_SIZE, "not present\n");
-        }
-    } else if ATTR_NAME_CMP("c2s_dma"){
-        if (kudev->cte.c2s_dma_present){
-            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.c2s_dma_channel_num);
-        } else {
-            return scnprintf(buf, PAGE_SIZE, "not present\n");
-        }
-    }
-    else if ATTR_NAME_CMP("irq_count"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_count);
-    } else if ATTR_NAME_CMP("irq_base_num"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_base_num);
-    } else if ATTR_NAME_CMP("core_num"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->core_num);
-    } else {
-        return 0;
-    }
-    #undef ATTR_NAME_CMP
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.offset);
+}
+static DEVICE_ATTR_RO(offset);
+
+static ssize_t size_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.length);
 }
+static DEVICE_ATTR_RO(size);
 
+static ssize_t type_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.type);
+}
+static DEVICE_ATTR_RO(type);
+
+static ssize_t s2c_dma_ch_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	return 0;
+}
+static DEVICE_ATTR_RO(s2c_dma_ch);
+
+static ssize_t c2s_dma_ch_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	return 0;
+}
+static DEVICE_ATTR_RO(c2s_dma_ch);
+
+static ssize_t s2c_dma_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
 
-DEVICE_ATTR(offset,  0444, show_attr, NULL);
-DEVICE_ATTR(size,    0444, show_attr, NULL);
-DEVICE_ATTR(type,    0444, show_attr, NULL);
-DEVICE_ATTR(s2c_dma_ch, 0444, show_attr, NULL);
-DEVICE_ATTR(c2s_dma_ch, 0444, show_attr, NULL);
-DEVICE_ATTR(s2c_dma, 0444, show_attr, NULL);
-DEVICE_ATTR(c2s_dma, 0444, show_attr, NULL);
-DEVICE_ATTR(irq_count, 0444, show_attr, NULL);
-DEVICE_ATTR(irq_base_num, 0444, show_attr, NULL);
-DEVICE_ATTR(core_num, 0444, show_attr, NULL);
-struct attribute * kpc_uio_class_attrs[] = {
+	if (!kudev->cte.s2c_dma_present)
+		return sprintf(buf, "%s", "not present\n");
+
+	return sprintf(buf, "%u\n", kudev->cte.s2c_dma_channel_num);
+}
+static DEVICE_ATTR_RO(s2c_dma);
+
+static ssize_t c2s_dma_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	if (!kudev->cte.c2s_dma_present)
+		return sprintf(buf, "%s", "not present\n");
+
+	return sprintf(buf, "%u\n", kudev->cte.c2s_dma_channel_num);
+}
+static DEVICE_ATTR_RO(c2s_dma);
+
+static ssize_t irq_count_show(struct device *dev, struct device_attribute *attr,
+			      char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.irq_count);
+}
+static DEVICE_ATTR_RO(irq_count);
+
+static ssize_t irq_base_num_show(struct device *dev,
+				 struct device_attribute *attr, char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.irq_base_num);
+}
+static DEVICE_ATTR_RO(irq_base_num);
+
+static ssize_t core_num_show(struct device *dev, struct device_attribute *attr,
+			     char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->core_num);
+}
+static DEVICE_ATTR_RO(core_num);
+
+struct attribute *kpc_uio_class_attrs[] = {
 	&dev_attr_offset.attr,
 	&dev_attr_size.attr,
 	&dev_attr_type.attr,
@@ -207,7 +251,6 @@ struct attribute * kpc_uio_class_attrs[] = {
 	NULL,
 };
 
-
 static
 int  kp2000_check_uio_irq(struct kp2000_device *pcard, u32 irq_num)
 {
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 2/8] staging: kpc2000: removed two kpc_uio_class device attributes.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH 3/8] staging: kpc2000: improved formatting of core.c Jeremy Sowden
                             ` (14 subsequent siblings)
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

The show functions of two attributes output nothing and they are unused.
Removed them.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Reported-by: Matt Sickler <matt.sickler@daktronics.com>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index 3339b84b8666..68d03f1d60f2 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -172,20 +172,6 @@ static ssize_t type_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(type);
 
-static ssize_t s2c_dma_ch_show(struct device *dev,
-			       struct device_attribute *attr, char *buf)
-{
-	return 0;
-}
-static DEVICE_ATTR_RO(s2c_dma_ch);
-
-static ssize_t c2s_dma_ch_show(struct device *dev,
-			       struct device_attribute *attr, char *buf)
-{
-	return 0;
-}
-static DEVICE_ATTR_RO(c2s_dma_ch);
-
 static ssize_t s2c_dma_show(struct device *dev, struct device_attribute *attr,
 			    char *buf)
 {
@@ -241,8 +227,6 @@ struct attribute *kpc_uio_class_attrs[] = {
 	&dev_attr_offset.attr,
 	&dev_attr_size.attr,
 	&dev_attr_type.attr,
-	&dev_attr_s2c_dma_ch.attr,
-	&dev_attr_c2s_dma_ch.attr,
 	&dev_attr_s2c_dma.attr,
 	&dev_attr_c2s_dma.attr,
 	&dev_attr_irq_count.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 3/8] staging: kpc2000: improved formatting of core.c.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
  2019-05-20 19:52           ` [PATCH 2/8] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH 4/8] staging: kpc2000: added a helper to get struct kp2000_device from struct device Jeremy Sowden
                             ` (13 subsequent siblings)
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

  * Indented with tabs.
  * Broke lines over 80 columns where possible.
  * Removed braces from one-statement blocks.
  * Tidied up some comments.
  * Removed multiple blank lines.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 810 ++++++++++++++-----------
 1 file changed, 445 insertions(+), 365 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index eb8bac62d33d..d4af5a643a7b 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -18,30 +18,52 @@
 #include <linux/jiffies.h>
 #include "pcie.h"
 
-
 /*******************************************************
-  * SysFS Attributes
-  ******************************************************/
-static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
+ * SysFS Attributes
+ ******************************************************/
+
+static ssize_t show_attr(struct device *dev, struct device_attribute *attr,
+			 char *buf)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
-    struct kp2000_device *pcard;
-
-    if (!pdev)  return -ENXIO;
-    pcard = pci_get_drvdata(pdev);
-    if (!pcard)  return -ENXIO;
-
-    if (strcmp("ssid", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);  } else
-    if (strcmp("ddna", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);  } else
-    if (strcmp("card_id", attr->attr.name) == 0){      return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);  } else
-    if (strcmp("hw_rev", attr->attr.name) == 0){       return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->hardware_revision);  } else
-    if (strcmp("build", attr->attr.name) == 0){        return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_version);  } else
-    if (strcmp("build_date", attr->attr.name) == 0){   return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_datestamp);  } else
-    if (strcmp("build_time", attr->attr.name) == 0){   return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_timestamp);  } else
-    { return -ENXIO; }
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct kp2000_device *pcard;
+
+	if (!pdev)
+		return -ENXIO;
+	pcard = pci_get_drvdata(pdev);
+	if (!pcard)
+		return -ENXIO;
+
+	if (strcmp("ssid", attr->attr.name) == 0)
+		return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);
+
+	if (strcmp("ddna", attr->attr.name) == 0)
+		return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);
+
+	if (strcmp("card_id", attr->attr.name) == 0)
+		return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);
+
+	if (strcmp("hw_rev", attr->attr.name) == 0)
+		return scnprintf(buf, PAGE_SIZE, "%08x\n",
+				 pcard->hardware_revision);
+
+	if (strcmp("build", attr->attr.name) == 0)
+		return scnprintf(buf, PAGE_SIZE, "%08x\n",
+				 pcard->build_version);
+
+	if (strcmp("build_date", attr->attr.name) == 0)
+		return scnprintf(buf, PAGE_SIZE, "%08x\n",
+				 pcard->build_datestamp);
+
+	if (strcmp("build_time", attr->attr.name) == 0)
+		return scnprintf(buf, PAGE_SIZE, "%08x\n",
+				 pcard->build_timestamp);
+
+	return -ENXIO;
 }
 
-static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t show_cpld_config_reg(struct device *dev,
+				    struct device_attribute *attr, char *buf)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
 	struct kp2000_device *pcard;
@@ -57,27 +79,33 @@ static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
 }
-static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+
+static ssize_t cpld_reconfigure(struct device *dev,
+				struct device_attribute *attr,
+				const char *buf, size_t count)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
-    long wr_val;
-    struct kp2000_device *pcard;
-    int rv;
-
-    if (!pdev)  return -ENXIO;
-    pcard = pci_get_drvdata(pdev);
-    if (!pcard)  return -ENXIO;
-
-    rv = kstrtol(buf, 0, &wr_val);
-    if (rv < 0)  return rv;
-    if (wr_val > 7)  return -EINVAL;
-
-    wr_val = wr_val << 8;
-    wr_val |= 0x1; // Set the "Configure Go" bit
-    writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
-    return count;
-}
+	struct pci_dev *pdev = to_pci_dev(dev);
+	long wr_val;
+	struct kp2000_device *pcard;
+	int rv;
 
+	if (!pdev)
+		return -ENXIO;
+	pcard = pci_get_drvdata(pdev);
+	if (!pcard)
+		return -ENXIO;
+
+	rv = kstrtol(buf, 0, &wr_val);
+	if (rv < 0)
+		return rv;
+	if (wr_val > 7)
+		return -EINVAL;
+
+	wr_val = wr_val << 8;
+	wr_val |= 0x1; // Set the "Configure Go" bit
+	writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
+	return count;
+}
 
 DEVICE_ATTR(ssid,       0444, show_attr, NULL);
 DEVICE_ATTR(ddna,       0444, show_attr, NULL);
@@ -89,349 +117,401 @@ DEVICE_ATTR(build_time, 0444, show_attr, NULL);
 DEVICE_ATTR(cpld_reg,   0444, show_cpld_config_reg, NULL);
 DEVICE_ATTR(cpld_reconfigure,   0220, NULL, cpld_reconfigure);
 
-static const struct attribute *  kp_attr_list[] = {
-    &dev_attr_ssid.attr,
-    &dev_attr_ddna.attr,
-    &dev_attr_card_id.attr,
-    &dev_attr_hw_rev.attr,
-    &dev_attr_build.attr,
-    &dev_attr_build_date.attr,
-    &dev_attr_build_time.attr,
-    &dev_attr_cpld_reg.attr,
-    &dev_attr_cpld_reconfigure.attr,
-    NULL,
+static const struct attribute *kp_attr_list[] = {
+	&dev_attr_ssid.attr,
+	&dev_attr_ddna.attr,
+	&dev_attr_card_id.attr,
+	&dev_attr_hw_rev.attr,
+	&dev_attr_build.attr,
+	&dev_attr_build_date.attr,
+	&dev_attr_build_time.attr,
+	&dev_attr_cpld_reg.attr,
+	&dev_attr_cpld_reconfigure.attr,
+	NULL,
 };
 
-
 /*******************************************************
-  * Functions
-  ******************************************************/
+ * Functions
+ ******************************************************/
 
 static void wait_and_read_ssid(struct kp2000_device *pcard)
 {
-    u64 read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
-    unsigned long timeout;
-
-    if (read_val & 0x8000000000000000){
-        pcard->ssid = read_val;
-        return;
-    }
-
-    timeout = jiffies + (HZ * 2);
-    do {
-        read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
-        if (read_val & 0x8000000000000000){
-            pcard->ssid = read_val;
-            return;
-        }
-        cpu_relax();
-        //schedule();
-    } while (time_before(jiffies, timeout));
-
-    dev_notice(&pcard->pdev->dev, "SSID didn't show up!\n");
-
-    #if 0
-    // Timed out waiting for the SSID to show up, just use the DDNA instead?
-    read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
-    pcard->ssid = read_val;
-    #else
-    // Timed out waiting for the SSID to show up, stick all zeros in the value
-    pcard->ssid = 0;
-    #endif
+	u64 read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
+	unsigned long timeout;
+
+	if (read_val & 0x8000000000000000) {
+		pcard->ssid = read_val;
+		return;
+	}
+
+	timeout = jiffies + (HZ * 2);
+	do {
+		read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
+		if (read_val & 0x8000000000000000) {
+			pcard->ssid = read_val;
+			return;
+		}
+		cpu_relax();
+		//schedule();
+	} while (time_before(jiffies, timeout));
+
+	dev_notice(&pcard->pdev->dev, "SSID didn't show up!\n");
+
+#if 0
+	// Timed out waiting for the SSID to show up, just use the DDNA instead?
+	read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
+	pcard->ssid = read_val;
+#else
+	// Timed out waiting for the SSID to show up, stick all zeros in the
+	// value
+	pcard->ssid = 0;
+#endif
 }
 
 static int  read_system_regs(struct kp2000_device *pcard)
 {
-    u64 read_val;
-
-    read_val = readq(pcard->sysinfo_regs_base + REG_MAGIC_NUMBER);
-    if (read_val != KP2000_MAGIC_VALUE){
-        dev_err(&pcard->pdev->dev, "Invalid magic!  Got: 0x%016llx  Want: 0x%016lx\n", read_val, KP2000_MAGIC_VALUE);
-        return -EILSEQ;
-    }
-
-    read_val = readq(pcard->sysinfo_regs_base + REG_CARD_ID_AND_BUILD);
-    pcard->card_id = (read_val & 0xFFFFFFFF00000000) >> 32;
-    pcard->build_version = (read_val & 0x00000000FFFFFFFF) >> 0;
-
-    read_val = readq(pcard->sysinfo_regs_base + REG_DATE_AND_TIME_STAMPS);
-    pcard->build_datestamp = (read_val & 0xFFFFFFFF00000000) >> 32;
-    pcard->build_timestamp = (read_val & 0x00000000FFFFFFFF) >> 0;
-
-    read_val = readq(pcard->sysinfo_regs_base + REG_CORE_TABLE_OFFSET);
-    pcard->core_table_length = (read_val & 0xFFFFFFFF00000000) >> 32;
-    pcard->core_table_offset = (read_val & 0x00000000FFFFFFFF) >> 0;
-
-    wait_and_read_ssid(pcard);
-
-    read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_HW_ID);
-    pcard->core_table_rev    = (read_val & 0x0000000000000F00) >> 8;
-    pcard->hardware_revision = (read_val & 0x000000000000001F);
-
-    read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
-    pcard->ddna = read_val;
-
-    dev_info(&pcard->pdev->dev, "system_regs: %08x %08x %08x %08x  %02x  %d %d  %016llx  %016llx\n",
-        pcard->card_id,
-        pcard->build_version,
-        pcard->build_datestamp,
-        pcard->build_timestamp,
-        pcard->hardware_revision,
-        pcard->core_table_rev,
-        pcard->core_table_length,
-        pcard->ssid,
-        pcard->ddna
-    );
-
-    if (pcard->core_table_rev > 1){
-        dev_err(&pcard->pdev->dev, "core table entry revision is higher than we can deal with, cannot continue with this card!\n");
-        return 1;
-    }
-
-    return 0;
+	u64 read_val;
+
+	read_val = readq(pcard->sysinfo_regs_base + REG_MAGIC_NUMBER);
+	if (read_val != KP2000_MAGIC_VALUE) {
+		dev_err(&pcard->pdev->dev,
+			"Invalid magic!  Got: 0x%016llx  Want: 0x%016lx\n",
+			read_val, KP2000_MAGIC_VALUE);
+		return -EILSEQ;
+	}
+
+	read_val = readq(pcard->sysinfo_regs_base + REG_CARD_ID_AND_BUILD);
+	pcard->card_id = (read_val & 0xFFFFFFFF00000000) >> 32;
+	pcard->build_version = (read_val & 0x00000000FFFFFFFF) >> 0;
+
+	read_val = readq(pcard->sysinfo_regs_base + REG_DATE_AND_TIME_STAMPS);
+	pcard->build_datestamp = (read_val & 0xFFFFFFFF00000000) >> 32;
+	pcard->build_timestamp = (read_val & 0x00000000FFFFFFFF) >> 0;
+
+	read_val = readq(pcard->sysinfo_regs_base + REG_CORE_TABLE_OFFSET);
+	pcard->core_table_length = (read_val & 0xFFFFFFFF00000000) >> 32;
+	pcard->core_table_offset = (read_val & 0x00000000FFFFFFFF) >> 0;
+
+	wait_and_read_ssid(pcard);
+
+	read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_HW_ID);
+	pcard->core_table_rev    = (read_val & 0x0000000000000F00) >> 8;
+	pcard->hardware_revision = (read_val & 0x000000000000001F);
+
+	read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
+	pcard->ddna = read_val;
+
+	dev_info(&pcard->pdev->dev,
+		 "system_regs: %08x %08x %08x %08x  %02x  %d %d  %016llx  %016llx\n",
+		 pcard->card_id,
+		 pcard->build_version,
+		 pcard->build_datestamp,
+		 pcard->build_timestamp,
+		 pcard->hardware_revision,
+		 pcard->core_table_rev,
+		 pcard->core_table_length,
+		 pcard->ssid,
+		 pcard->ddna);
+
+	if (pcard->core_table_rev > 1) {
+		dev_err(&pcard->pdev->dev,
+			"core table entry revision is higher than we can deal with, cannot continue with this card!\n");
+		return 1;
+	}
+
+	return 0;
 }
 
-irqreturn_t  kp2000_irq_handler(int irq, void *dev_id)
+irqreturn_t kp2000_irq_handler(int irq, void *dev_id)
 {
-    struct kp2000_device  *pcard = (struct kp2000_device*)dev_id;
-    SetBackEndControl(pcard->dma_common_regs, KPC_DMA_CARD_IRQ_ENABLE | KPC_DMA_CARD_USER_INTERRUPT_MODE | KPC_DMA_CARD_USER_INTERRUPT_ACTIVE);
-    return IRQ_HANDLED;
+	struct kp2000_device *pcard = (struct kp2000_device *)dev_id;
+
+	SetBackEndControl(pcard->dma_common_regs,
+			  KPC_DMA_CARD_IRQ_ENABLE |
+			  KPC_DMA_CARD_USER_INTERRUPT_MODE |
+			  KPC_DMA_CARD_USER_INTERRUPT_ACTIVE);
+	return IRQ_HANDLED;
 }
 
-int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+int kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
-    int err = 0;
-    struct kp2000_device *pcard;
-    static int card_count = 1;
-    int rv;
-    unsigned long reg_bar_phys_addr;
-    unsigned long reg_bar_phys_len;
-    unsigned long dma_bar_phys_addr;
-    unsigned long dma_bar_phys_len;
-    u16 regval;
-
-    dev_dbg(&pdev->dev, "kp2000_pcie_probe(pdev = [%p], id = [%p])\n", pdev, id);
-
-    //{ Step 1: Allocate a struct for the pcard
-    pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);
-    if (NULL == pcard){
-        dev_err(&pdev->dev, "probe: failed to allocate private card data\n");
-        return -ENOMEM;
-    }
-    dev_dbg(&pdev->dev, "probe: allocated struct kp2000_device @ %p\n", pcard);
-    //}
-
-    //{ Step 2: Initialize trivial pcard elements
-    pcard->card_num = card_count;
-    card_count++;
-    scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
-
-    mutex_init(&pcard->sem);
-    lock_card(pcard);
-
-    pcard->pdev = pdev;
-    pci_set_drvdata(pdev, pcard);
-    //}
-
-    //{ Step 3: Enable PCI device
-    err = pci_enable_device(pcard->pdev);
-    if (err){
-        dev_err(&pcard->pdev->dev, "probe: failed to enable PCIE2000 PCIe device (%d)\n", err);
-        goto out3;
-    }
-    //}
-
-    //{ Step 4: Setup the Register BAR
-    reg_bar_phys_addr = pci_resource_start(pcard->pdev, REG_BAR);
-    reg_bar_phys_len = pci_resource_len(pcard->pdev, REG_BAR);
-
-    pcard->regs_bar_base = ioremap_nocache(reg_bar_phys_addr, PAGE_SIZE);
-    if (NULL == pcard->regs_bar_base){
-        dev_err(&pcard->pdev->dev, "probe: REG_BAR could not remap memory to virtual space\n");
-        err = -ENODEV;
-        goto out4;
-    }
-    dev_dbg(&pcard->pdev->dev, "probe: REG_BAR virt hardware address start [%p]\n", pcard->regs_bar_base);
-
-    err = pci_request_region(pcard->pdev, REG_BAR, KP_DRIVER_NAME_KP2000);
-    if (err){
-        iounmap(pcard->regs_bar_base);
-        dev_err(&pcard->pdev->dev, "probe: failed to acquire PCI region (%d)\n", err);
-        err = -ENODEV;
-        goto out4;
-    }
-
-    pcard->regs_base_resource.start = reg_bar_phys_addr;
-    pcard->regs_base_resource.end   = reg_bar_phys_addr + reg_bar_phys_len - 1;
-    pcard->regs_base_resource.flags = IORESOURCE_MEM;
-    //}
-
-    //{ Step 5: Setup the DMA BAR
-    dma_bar_phys_addr = pci_resource_start(pcard->pdev, DMA_BAR);
-    dma_bar_phys_len = pci_resource_len(pcard->pdev, DMA_BAR);
-
-    pcard->dma_bar_base = ioremap_nocache(dma_bar_phys_addr, dma_bar_phys_len);
-    if (NULL == pcard->dma_bar_base){
-        dev_err(&pcard->pdev->dev, "probe: DMA_BAR could not remap memory to virtual space\n");
-        err = -ENODEV;
-        goto out5;
-    }
-    dev_dbg(&pcard->pdev->dev, "probe: DMA_BAR virt hardware address start [%p]\n", pcard->dma_bar_base);
-
-    pcard->dma_common_regs = pcard->dma_bar_base + KPC_DMA_COMMON_OFFSET;
-
-    err = pci_request_region(pcard->pdev, DMA_BAR, "kp2000_pcie");
-    if (err){
-        iounmap(pcard->dma_bar_base);
-        dev_err(&pcard->pdev->dev, "probe: failed to acquire PCI region (%d)\n", err);
-        err = -ENODEV;
-        goto out5;
-    }
-
-    pcard->dma_base_resource.start = dma_bar_phys_addr;
-    pcard->dma_base_resource.end   = dma_bar_phys_addr + dma_bar_phys_len - 1;
-    pcard->dma_base_resource.flags = IORESOURCE_MEM;
-    //}
-
-    //{ Step 6: System Regs
-    pcard->sysinfo_regs_base = pcard->regs_bar_base;
-    err = read_system_regs(pcard);
-    if (err)
-        goto out6;
-
-    // Disable all "user" interrupts because they're not used yet.
-    writeq(0xFFFFFFFFFFFFFFFF, pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
-    //}
-
-    //{ Step 7: Configure PCI thingies
-    // let the card master PCIe
-    pci_set_master(pcard->pdev);
-    // enable IO and mem if not already done
-    pci_read_config_word(pcard->pdev, PCI_COMMAND, &regval);
-    regval |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
-    pci_write_config_word(pcard->pdev, PCI_COMMAND, regval);
-
-    // Clear relaxed ordering bit
-    pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN, 0);
-
-    // Set Max_Payload_Size and Max_Read_Request_Size
-    regval = (0x0) << 5; // Max_Payload_Size = 128 B
-    pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_PAYLOAD, regval);
-    regval = (0x0) << 12; // Max_Read_Request_Size = 128 B
-    pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_READRQ, regval);
-
-    // Enable error reporting for: Correctable Errors, Non-Fatal Errors, Fatal Errors, Unsupported Requests
-    pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, 0, PCI_EXP_DEVCTL_CERE | PCI_EXP_DEVCTL_NFERE | PCI_EXP_DEVCTL_FERE | PCI_EXP_DEVCTL_URRE);
-
-    err = dma_set_mask(PCARD_TO_DEV(pcard), DMA_BIT_MASK(64));
-    if (err){
-        dev_err(&pcard->pdev->dev, "CANNOT use DMA mask %0llx\n", DMA_BIT_MASK(64));
-        goto out7;
-    }
-    dev_dbg(&pcard->pdev->dev, "Using DMA mask %0llx\n", dma_get_mask(PCARD_TO_DEV(pcard)));
-    //}
-
-    //{ Step 8: Configure IRQs
-    err = pci_enable_msi(pcard->pdev);
-    if (err < 0)
-        goto out8a;
-
-    rv = request_irq(pcard->pdev->irq, kp2000_irq_handler, IRQF_SHARED, pcard->name, pcard);
-    if (rv){
-        dev_err(&pcard->pdev->dev, "kp2000_pcie_probe: failed to request_irq: %d\n", rv);
-        goto out8b;
-    }
-    //}
-
-    //{ Step 9: Setup sysfs attributes
-    err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);
-    if (err){
-        dev_err(&pdev->dev, "Failed to add sysfs files: %d\n", err);
-        goto out9;
-    }
-    //}
-
-    //{ Step 10: Setup misc device
-    pcard->miscdev.minor = MISC_DYNAMIC_MINOR;
-    pcard->miscdev.fops = &kp2000_fops;
-    pcard->miscdev.parent = &pcard->pdev->dev;
-    pcard->miscdev.name = pcard->name;
-
-    err = misc_register(&pcard->miscdev);
-    if (err){
-        dev_err(&pcard->pdev->dev, "kp2000_pcie_probe: misc_register failed: %d\n", err);
-        goto out10;
-    }
-    //}
-
-    //{ Step 11: Probe cores
-    err = kp2000_probe_cores(pcard);
-    if (err)
-        goto out11;
-    //}
-
-    //{ Step 12: Enable IRQs in HW
-    SetBackEndControl(pcard->dma_common_regs, KPC_DMA_CARD_IRQ_ENABLE | KPC_DMA_CARD_USER_INTERRUPT_MODE);
-    //}
-
-    dev_dbg(&pcard->pdev->dev, "kp2000_pcie_probe() complete!\n");
-    unlock_card(pcard);
-    return 0;
-
-  out11:
-    misc_deregister(&pcard->miscdev);
-  out10:
-    sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
-  out9:
-    free_irq(pcard->pdev->irq, pcard);
-  out8b:
-    pci_disable_msi(pcard->pdev);
-  out8a:
-  out7:
-  out6:
-    iounmap(pcard->dma_bar_base);
-    pci_release_region(pdev, DMA_BAR);
-    pcard->dma_bar_base = NULL;
-  out5:
-    iounmap(pcard->regs_bar_base);
-    pci_release_region(pdev, REG_BAR);
-    pcard->regs_bar_base = NULL;
-  out4:
-    pci_disable_device(pcard->pdev);
-  out3:
-    unlock_card(pcard);
-    kfree(pcard);
-    return err;
+	int err = 0;
+	struct kp2000_device *pcard;
+	static int card_count = 1;
+	int rv;
+	unsigned long reg_bar_phys_addr;
+	unsigned long reg_bar_phys_len;
+	unsigned long dma_bar_phys_addr;
+	unsigned long dma_bar_phys_len;
+	u16 regval;
+
+	dev_dbg(&pdev->dev, "kp2000_pcie_probe(pdev = [%p], id = [%p])\n",
+		pdev, id);
+
+	/*
+	 * Step 1: Allocate a struct for the pcard
+	 */
+	pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);
+	if (NULL == pcard) {
+		dev_err(&pdev->dev,
+			"probe: failed to allocate private card data\n");
+		return -ENOMEM;
+	}
+	dev_dbg(&pdev->dev, "probe: allocated struct kp2000_device @ %p\n",
+		pcard);
+
+	/*
+	 * Step 2: Initialize trivial pcard elements
+	 */
+	pcard->card_num = card_count;
+	card_count++;
+	scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
+
+	mutex_init(&pcard->sem);
+	lock_card(pcard);
+
+	pcard->pdev = pdev;
+	pci_set_drvdata(pdev, pcard);
+
+	/*
+	 * Step 3: Enable PCI device
+	 */
+	err = pci_enable_device(pcard->pdev);
+	if (err) {
+		dev_err(&pcard->pdev->dev,
+			"probe: failed to enable PCIE2000 PCIe device (%d)\n",
+			err);
+		goto out3;
+	}
+
+	/*
+	 * Step 4: Setup the Register BAR
+	 */
+	reg_bar_phys_addr = pci_resource_start(pcard->pdev, REG_BAR);
+	reg_bar_phys_len = pci_resource_len(pcard->pdev, REG_BAR);
+
+	pcard->regs_bar_base = ioremap_nocache(reg_bar_phys_addr, PAGE_SIZE);
+	if (NULL == pcard->regs_bar_base) {
+		dev_err(&pcard->pdev->dev,
+			"probe: REG_BAR could not remap memory to virtual space\n");
+		err = -ENODEV;
+		goto out4;
+	}
+	dev_dbg(&pcard->pdev->dev,
+		"probe: REG_BAR virt hardware address start [%p]\n",
+		pcard->regs_bar_base);
+
+	err = pci_request_region(pcard->pdev, REG_BAR, KP_DRIVER_NAME_KP2000);
+	if (err) {
+		iounmap(pcard->regs_bar_base);
+		dev_err(&pcard->pdev->dev,
+			"probe: failed to acquire PCI region (%d)\n",
+			err);
+		err = -ENODEV;
+		goto out4;
+	}
+
+	pcard->regs_base_resource.start = reg_bar_phys_addr;
+	pcard->regs_base_resource.end   = reg_bar_phys_addr +
+					  reg_bar_phys_len - 1;
+	pcard->regs_base_resource.flags = IORESOURCE_MEM;
+
+	/*
+	 * Step 5: Setup the DMA BAR
+	 */
+	dma_bar_phys_addr = pci_resource_start(pcard->pdev, DMA_BAR);
+	dma_bar_phys_len = pci_resource_len(pcard->pdev, DMA_BAR);
+
+	pcard->dma_bar_base = ioremap_nocache(dma_bar_phys_addr,
+					      dma_bar_phys_len);
+	if (NULL == pcard->dma_bar_base) {
+		dev_err(&pcard->pdev->dev,
+			"probe: DMA_BAR could not remap memory to virtual space\n");
+		err = -ENODEV;
+		goto out5;
+	}
+	dev_dbg(&pcard->pdev->dev,
+		"probe: DMA_BAR virt hardware address start [%p]\n",
+		pcard->dma_bar_base);
+
+	pcard->dma_common_regs = pcard->dma_bar_base + KPC_DMA_COMMON_OFFSET;
+
+	err = pci_request_region(pcard->pdev, DMA_BAR, "kp2000_pcie");
+	if (err) {
+		iounmap(pcard->dma_bar_base);
+		dev_err(&pcard->pdev->dev,
+			"probe: failed to acquire PCI region (%d)\n", err);
+		err = -ENODEV;
+		goto out5;
+	}
+
+	pcard->dma_base_resource.start = dma_bar_phys_addr;
+	pcard->dma_base_resource.end   = dma_bar_phys_addr +
+					 dma_bar_phys_len - 1;
+	pcard->dma_base_resource.flags = IORESOURCE_MEM;
+
+	/*
+	 * Step 6: System Regs
+	 */
+	pcard->sysinfo_regs_base = pcard->regs_bar_base;
+	err = read_system_regs(pcard);
+	if (err)
+		goto out6;
+
+	// Disable all "user" interrupts because they're not used yet.
+	writeq(0xFFFFFFFFFFFFFFFF,
+	       pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
+
+	/*
+	 * Step 7: Configure PCI thingies
+	 */
+	// let the card master PCIe
+	pci_set_master(pcard->pdev);
+	// enable IO and mem if not already done
+	pci_read_config_word(pcard->pdev, PCI_COMMAND, &regval);
+	regval |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
+	pci_write_config_word(pcard->pdev, PCI_COMMAND, regval);
+
+	// Clear relaxed ordering bit
+	pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL,
+					   PCI_EXP_DEVCTL_RELAX_EN, 0);
+
+	// Set Max_Payload_Size and Max_Read_Request_Size
+	regval = (0x0) << 5; // Max_Payload_Size = 128 B
+	pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL,
+					   PCI_EXP_DEVCTL_PAYLOAD, regval);
+	regval = (0x0) << 12; // Max_Read_Request_Size = 128 B
+	pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL,
+					   PCI_EXP_DEVCTL_READRQ, regval);
+
+	// Enable error reporting for: Correctable Errors, Non-Fatal Errors,
+	// Fatal Errors, Unsupported Requests
+	pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, 0,
+					   PCI_EXP_DEVCTL_CERE |
+					   PCI_EXP_DEVCTL_NFERE |
+					   PCI_EXP_DEVCTL_FERE |
+					   PCI_EXP_DEVCTL_URRE);
+
+	err = dma_set_mask(PCARD_TO_DEV(pcard), DMA_BIT_MASK(64));
+	if (err) {
+		dev_err(&pcard->pdev->dev,
+			"CANNOT use DMA mask %0llx\n", DMA_BIT_MASK(64));
+		goto out7;
+	}
+	dev_dbg(&pcard->pdev->dev,
+		"Using DMA mask %0llx\n", dma_get_mask(PCARD_TO_DEV(pcard)));
+
+	/*
+	 * Step 8: Configure IRQs
+	 */
+	err = pci_enable_msi(pcard->pdev);
+	if (err < 0)
+		goto out8a;
+
+	rv = request_irq(pcard->pdev->irq, kp2000_irq_handler, IRQF_SHARED,
+			 pcard->name, pcard);
+	if (rv) {
+		dev_err(&pcard->pdev->dev,
+			"kp2000_pcie_probe: failed to request_irq: %d\n", rv);
+		goto out8b;
+	}
+
+	/*
+	 * Step 9: Setup sysfs attributes
+	 */
+	err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);
+	if (err) {
+		dev_err(&pdev->dev, "Failed to add sysfs files: %d\n", err);
+		goto out9;
+	}
+
+	/*
+	 * Step 10: Setup misc device
+	 */
+	pcard->miscdev.minor = MISC_DYNAMIC_MINOR;
+	pcard->miscdev.fops = &kp2000_fops;
+	pcard->miscdev.parent = &pcard->pdev->dev;
+	pcard->miscdev.name = pcard->name;
+
+	err = misc_register(&pcard->miscdev);
+	if (err) {
+		dev_err(&pcard->pdev->dev,
+			"kp2000_pcie_probe: misc_register failed: %d\n", err);
+		goto out10;
+	}
+
+	/*
+	 * Step 11: Probe cores
+	 */
+	err = kp2000_probe_cores(pcard);
+	if (err)
+		goto out11;
+
+	/*
+	 * Step 12: Enable IRQs in HW
+	 */
+	SetBackEndControl(pcard->dma_common_regs,
+			  KPC_DMA_CARD_IRQ_ENABLE |
+			  KPC_DMA_CARD_USER_INTERRUPT_MODE);
+
+	dev_dbg(&pcard->pdev->dev, "kp2000_pcie_probe() complete!\n");
+	unlock_card(pcard);
+	return 0;
+
+out11:
+	misc_deregister(&pcard->miscdev);
+out10:
+	sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
+out9:
+	free_irq(pcard->pdev->irq, pcard);
+out8b:
+	pci_disable_msi(pcard->pdev);
+out8a:
+out7:
+out6:
+	iounmap(pcard->dma_bar_base);
+	pci_release_region(pdev, DMA_BAR);
+	pcard->dma_bar_base = NULL;
+out5:
+	iounmap(pcard->regs_bar_base);
+	pci_release_region(pdev, REG_BAR);
+	pcard->regs_bar_base = NULL;
+out4:
+	pci_disable_device(pcard->pdev);
+out3:
+	unlock_card(pcard);
+	kfree(pcard);
+	return err;
 }
 
-
-void  kp2000_pcie_remove(struct pci_dev *pdev)
+void kp2000_pcie_remove(struct pci_dev *pdev)
 {
-    struct kp2000_device *pcard = pci_get_drvdata(pdev);
-
-    dev_dbg(&pdev->dev, "kp2000_pcie_remove(pdev=%p)\n", pdev);
-
-    if (pcard == NULL)  return;
-
-    lock_card(pcard);
-    kp2000_remove_cores(pcard);
-    mfd_remove_devices(PCARD_TO_DEV(pcard));
-    misc_deregister(&pcard->miscdev);
-    sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
-    free_irq(pcard->pdev->irq, pcard);
-    pci_disable_msi(pcard->pdev);
-    if (pcard->dma_bar_base != NULL){
-        iounmap(pcard->dma_bar_base);
-        pci_release_region(pdev, DMA_BAR);
-        pcard->dma_bar_base = NULL;
-    }
-    if (pcard->regs_bar_base != NULL){
-        iounmap(pcard->regs_bar_base);
-        pci_release_region(pdev, REG_BAR);
-        pcard->regs_bar_base = NULL;
-    }
-    pci_disable_device(pcard->pdev);
-    pci_set_drvdata(pdev, NULL);
-    unlock_card(pcard);
-    kfree(pcard);
+	struct kp2000_device *pcard = pci_get_drvdata(pdev);
+
+	dev_dbg(&pdev->dev, "kp2000_pcie_remove(pdev=%p)\n", pdev);
+
+	if (pcard == NULL)
+		return;
+
+	lock_card(pcard);
+	kp2000_remove_cores(pcard);
+	mfd_remove_devices(PCARD_TO_DEV(pcard));
+	misc_deregister(&pcard->miscdev);
+	sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
+	free_irq(pcard->pdev->irq, pcard);
+	pci_disable_msi(pcard->pdev);
+	if (pcard->dma_bar_base != NULL) {
+		iounmap(pcard->dma_bar_base);
+		pci_release_region(pdev, DMA_BAR);
+		pcard->dma_bar_base = NULL;
+	}
+	if (pcard->regs_bar_base != NULL) {
+		iounmap(pcard->regs_bar_base);
+		pci_release_region(pdev, REG_BAR);
+		pcard->regs_bar_base = NULL;
+	}
+	pci_disable_device(pcard->pdev);
+	pci_set_drvdata(pdev, NULL);
+	unlock_card(pcard);
+	kfree(pcard);
 }
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 4/8] staging: kpc2000: added a helper to get struct kp2000_device from struct device.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
  2019-05-20 19:52           ` [PATCH 2/8] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
  2019-05-20 19:52           ` [PATCH 3/8] staging: kpc2000: improved formatting of core.c Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH 5/8] staging: kpc2000: added separate show functions for readable kp device attributes, defined them as read-only, and declared them static Jeremy Sowden
                             ` (12 subsequent siblings)
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

The attribute call-backs all use the same formula to get the pcard from
dev:

  struct pci_dev *pdev = to_pci_dev(dev);
  struct kp2000_device *pcard;

  if (!pdev)
    return -ENXIO;
  pcard = pci_get_drvdata(pdev);
  if (!pcard)
    return -ENXIO;

Added a function to reduce the duplicated code.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 29 ++++++++++++--------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index d4af5a643a7b..c33595cc1332 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -22,15 +22,21 @@
  * SysFS Attributes
  ******************************************************/
 
-static ssize_t show_attr(struct device *dev, struct device_attribute *attr,
-			 char *buf)
+static struct kp2000_device *get_pcard(struct device *dev)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
-	struct kp2000_device *pcard;
 
 	if (!pdev)
-		return -ENXIO;
-	pcard = pci_get_drvdata(pdev);
+		return NULL;
+
+	return pci_get_drvdata(pdev);
+}
+
+static ssize_t show_attr(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kp2000_device *pcard = get_pcard(dev);
+
 	if (!pcard)
 		return -ENXIO;
 
@@ -65,14 +71,9 @@ static ssize_t show_attr(struct device *dev, struct device_attribute *attr,
 static ssize_t show_cpld_config_reg(struct device *dev,
 				    struct device_attribute *attr, char *buf)
 {
-	struct pci_dev *pdev = to_pci_dev(dev);
-	struct kp2000_device *pcard;
+	struct kp2000_device *pcard = get_pcard(dev);
 	u64 val;
 
-	if (!pdev)
-		return -ENXIO;
-
-	pcard = pci_get_drvdata(pdev);
 	if (!pcard)
 		return -ENXIO;
 
@@ -84,14 +85,10 @@ static ssize_t cpld_reconfigure(struct device *dev,
 				struct device_attribute *attr,
 				const char *buf, size_t count)
 {
-	struct pci_dev *pdev = to_pci_dev(dev);
+	struct kp2000_device *pcard = get_pcard(dev);
 	long wr_val;
-	struct kp2000_device *pcard;
 	int rv;
 
-	if (!pdev)
-		return -ENXIO;
-	pcard = pci_get_drvdata(pdev);
 	if (!pcard)
 		return -ENXIO;
 
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 5/8] staging: kpc2000: added separate show functions for readable kp device attributes, defined them as read-only, and declared them static.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                             ` (2 preceding siblings ...)
  2019-05-20 19:52           ` [PATCH 4/8] staging: kpc2000: added a helper to get struct kp2000_device from struct device Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH 6/8] staging: kpc2000: use IDA to assign card numbers Jeremy Sowden
                             ` (11 subsequent siblings)
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Defineed separate simple show functions for each attribute instead of
having a one big one containing a chain of conditionals.

Replaced calls to scnprintf with sprintf since all the outputs are
single integers.

All the readable device attributes are read-only, so used DEVICE_ATTR_RO
to define them.

The definitions are only used to populate the kp_attr_list attribute
array, so declared them as static.

Fixes the following sparse warnings:

  drivers/staging/kpc2000/kpc2000/core.c:152:1: warning: symbol 'dev_attr_ssid' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:153:1: warning: symbol 'dev_attr_ddna' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:154:1: warning: symbol 'dev_attr_card_id' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:155:1: warning: symbol 'dev_attr_hw_rev' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:156:1: warning: symbol 'dev_attr_build' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:157:1: warning: symbol 'dev_attr_build_date' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:158:1: warning: symbol 'dev_attr_build_time' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:159:1: warning: symbol 'dev_attr_cpld_reg' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:161:1: warning: symbol 'dev_attr_cpld_reconfigure' was not declared. Should it be static?

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 106 +++++++++++++++++--------
 1 file changed, 73 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index c33595cc1332..38de7e7a824d 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -32,7 +32,7 @@ static struct kp2000_device *get_pcard(struct device *dev)
 	return pci_get_drvdata(pdev);
 }
 
-static ssize_t show_attr(struct device *dev, struct device_attribute *attr,
+static ssize_t ssid_show(struct device *dev, struct device_attribute *attr,
 			 char *buf)
 {
 	struct kp2000_device *pcard = get_pcard(dev);
@@ -40,36 +40,84 @@ static ssize_t show_attr(struct device *dev, struct device_attribute *attr,
 	if (!pcard)
 		return -ENXIO;
 
-	if (strcmp("ssid", attr->attr.name) == 0)
-		return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);
+	return sprintf(buf, "%016llx\n", pcard->ssid);
+}
+static DEVICE_ATTR_RO(ssid);
 
-	if (strcmp("ddna", attr->attr.name) == 0)
-		return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);
+static ssize_t ddna_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kp2000_device *pcard = get_pcard(dev);
 
-	if (strcmp("card_id", attr->attr.name) == 0)
-		return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);
+	if (!pcard)
+		return -ENXIO;
+
+	return sprintf(buf, "%016llx\n", pcard->ddna);
+}
+static DEVICE_ATTR_RO(ddna);
+
+static ssize_t card_id_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kp2000_device *pcard = get_pcard(dev);
 
-	if (strcmp("hw_rev", attr->attr.name) == 0)
-		return scnprintf(buf, PAGE_SIZE, "%08x\n",
-				 pcard->hardware_revision);
+	if (!pcard)
+		return -ENXIO;
 
-	if (strcmp("build", attr->attr.name) == 0)
-		return scnprintf(buf, PAGE_SIZE, "%08x\n",
-				 pcard->build_version);
+	return sprintf(buf, "%08x\n", pcard->card_id);
+}
+static DEVICE_ATTR_RO(card_id);
 
-	if (strcmp("build_date", attr->attr.name) == 0)
-		return scnprintf(buf, PAGE_SIZE, "%08x\n",
-				 pcard->build_datestamp);
+static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
+{
+	struct kp2000_device *pcard = get_pcard(dev);
 
-	if (strcmp("build_time", attr->attr.name) == 0)
-		return scnprintf(buf, PAGE_SIZE, "%08x\n",
-				 pcard->build_timestamp);
+	if (!pcard)
+		return -ENXIO;
 
-	return -ENXIO;
+	return sprintf(buf, "%08x\n", pcard->hardware_revision);
 }
+static DEVICE_ATTR_RO(hw_rev);
 
-static ssize_t show_cpld_config_reg(struct device *dev,
-				    struct device_attribute *attr, char *buf)
+static ssize_t build_show(struct device *dev, struct device_attribute *attr,
+			  char *buf)
+{
+	struct kp2000_device *pcard = get_pcard(dev);
+
+	if (!pcard)
+		return -ENXIO;
+
+	return sprintf(buf, "%08x\n", pcard->build_version);
+}
+static DEVICE_ATTR_RO(build);
+
+static ssize_t build_date_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct kp2000_device *pcard = get_pcard(dev);
+
+	if (!pcard)
+		return -ENXIO;
+
+	return sprintf(buf, "%08x\n", pcard->build_datestamp);
+}
+static DEVICE_ATTR_RO(build_date);
+
+static ssize_t build_time_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct kp2000_device *pcard = get_pcard(dev);
+
+	if (!pcard)
+		return -ENXIO;
+
+	return sprintf(buf, "%08x\n", pcard->build_timestamp);
+}
+static DEVICE_ATTR_RO(build_time);
+
+static ssize_t cpld_reg_show(struct device *dev, struct device_attribute *attr,
+			     char *buf)
 {
 	struct kp2000_device *pcard = get_pcard(dev);
 	u64 val;
@@ -78,8 +126,9 @@ static ssize_t show_cpld_config_reg(struct device *dev,
 		return -ENXIO;
 
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
-	return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
+	return sprintf(buf, "%016llx\n", val);
 }
+static DEVICE_ATTR_RO(cpld_reg);
 
 static ssize_t cpld_reconfigure(struct device *dev,
 				struct device_attribute *attr,
@@ -103,16 +152,7 @@ static ssize_t cpld_reconfigure(struct device *dev,
 	writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	return count;
 }
-
-DEVICE_ATTR(ssid,       0444, show_attr, NULL);
-DEVICE_ATTR(ddna,       0444, show_attr, NULL);
-DEVICE_ATTR(card_id,    0444, show_attr, NULL);
-DEVICE_ATTR(hw_rev,     0444, show_attr, NULL);
-DEVICE_ATTR(build,      0444, show_attr, NULL);
-DEVICE_ATTR(build_date, 0444, show_attr, NULL);
-DEVICE_ATTR(build_time, 0444, show_attr, NULL);
-DEVICE_ATTR(cpld_reg,   0444, show_cpld_config_reg, NULL);
-DEVICE_ATTR(cpld_reconfigure,   0220, NULL, cpld_reconfigure);
+static DEVICE_ATTR(cpld_reconfigure, 0220, NULL, cpld_reconfigure);
 
 static const struct attribute *kp_attr_list[] = {
 	&dev_attr_ssid.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 6/8] staging: kpc2000: use IDA to assign card numbers.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                             ` (3 preceding siblings ...)
  2019-05-20 19:52           ` [PATCH 5/8] staging: kpc2000: added separate show functions for readable kp device attributes, defined them as read-only, and declared them static Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH 7/8] staging: kpc2000: simplified kp2000_device retrieval in device attribute call-backs Jeremy Sowden
                             ` (10 subsequent siblings)
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Previously the next card number was assigned from a static int local
variable.  Replaced it with an IDA.  Avoids the assignment of ever-
increasing card-numbers by allowing them to be reused.

Updated TODO.

Corrected format-specifier for unsigned pcard->card_num.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/TODO                  |  1 -
 drivers/staging/kpc2000/kpc2000/core.c        | 23 +++++++++++++++----
 .../staging/kpc2000/kpc2000/kp2000_module.c   |  1 +
 drivers/staging/kpc2000/kpc2000/pcie.h        |  9 ++++----
 4 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/kpc2000/TODO b/drivers/staging/kpc2000/TODO
index 669fe5bf9637..47530e23e940 100644
--- a/drivers/staging/kpc2000/TODO
+++ b/drivers/staging/kpc2000/TODO
@@ -1,6 +1,5 @@
 - the kpc_spi driver doesn't seem to let multiple transactions (to different instances of the core) happen in parallel...
 - The kpc_i2c driver is a hot mess, it should probably be cleaned up a ton.  It functions against current hardware though.
-- pcard->card_num in kp2000_pcie_probe() is a global variable and needs atomic / locking / something better.
 - would be nice if the AIO fileops in kpc_dma could be made to work
     - probably want to add a CONFIG_ option to control compilation of the AIO functions
 - if the AIO fileops in kpc_dma start working, next would be making iov_count > 1 work too
diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index 38de7e7a824d..a8383e8159eb 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0+
+#include <linux/idr.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/pci.h>
@@ -18,6 +19,8 @@
 #include <linux/jiffies.h>
 #include "pcie.h"
 
+static DEFINE_IDA(card_num_ida);
+
 /*******************************************************
  * SysFS Attributes
  ******************************************************/
@@ -274,7 +277,6 @@ int kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	int err = 0;
 	struct kp2000_device *pcard;
-	static int card_count = 1;
 	int rv;
 	unsigned long reg_bar_phys_addr;
 	unsigned long reg_bar_phys_len;
@@ -300,9 +302,14 @@ int kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	/*
 	 * Step 2: Initialize trivial pcard elements
 	 */
-	pcard->card_num = card_count;
-	card_count++;
-	scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
+	err = ida_simple_get(&card_num_ida, 1, INT_MAX, GFP_KERNEL);
+	if (err < 0) {
+		dev_err(&pdev->dev, "probe: failed to get card number (%d)\n",
+			err);
+		goto out2;
+	}
+	pcard->card_num = err;
+	scnprintf(pcard->name, 16, "kpcard%u", pcard->card_num);
 
 	mutex_init(&pcard->sem);
 	lock_card(pcard);
@@ -517,6 +524,8 @@ int kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	pci_disable_device(pcard->pdev);
 out3:
 	unlock_card(pcard);
+	ida_simple_remove(&card_num_ida, pcard->card_num);
+out2:
 	kfree(pcard);
 	return err;
 }
@@ -550,5 +559,11 @@ void kp2000_pcie_remove(struct pci_dev *pdev)
 	pci_disable_device(pcard->pdev);
 	pci_set_drvdata(pdev, NULL);
 	unlock_card(pcard);
+	ida_simple_remove(&card_num_ida, pcard->card_num);
 	kfree(pcard);
 }
+
+void kp2000_pcie_destroy(void)
+{
+	ida_destroy(&card_num_ida);
+}
diff --git a/drivers/staging/kpc2000/kpc2000/kp2000_module.c b/drivers/staging/kpc2000/kpc2000/kp2000_module.c
index fa3bd266ba54..8da8d5f5f8cc 100644
--- a/drivers/staging/kpc2000/kpc2000/kp2000_module.c
+++ b/drivers/staging/kpc2000/kpc2000/kp2000_module.c
@@ -50,5 +50,6 @@ static void __exit  kp2000_pcie_exit(void)
 {
 	pci_unregister_driver(&kp2000_driver_inst);
 	class_destroy(kpc_uio_class);
+	kp2000_pcie_destroy();
 }
 module_exit(kp2000_pcie_exit);
diff --git a/drivers/staging/kpc2000/kpc2000/pcie.h b/drivers/staging/kpc2000/kpc2000/pcie.h
index 8a032a5a962e..b416b792250b 100644
--- a/drivers/staging/kpc2000/kpc2000/pcie.h
+++ b/drivers/staging/kpc2000/kpc2000/pcie.h
@@ -84,10 +84,11 @@ struct kp2000_device {
 extern struct class *kpc_uio_class;
 extern struct attribute *kpc_uio_class_attrs[];
 
-int   kp2000_pcie_probe(struct pci_dev *dev, const struct pci_device_id *id);
-void  kp2000_pcie_remove(struct pci_dev *pdev);
-int   kp2000_probe_cores(struct kp2000_device *pcard);
-void  kp2000_remove_cores(struct kp2000_device *pcard);
+int  kp2000_pcie_probe(struct pci_dev *dev, const struct pci_device_id *id);
+void kp2000_pcie_remove(struct pci_dev *pdev);
+void kp2000_pcie_destroy(void);
+int  kp2000_probe_cores(struct kp2000_device *pcard);
+void kp2000_remove_cores(struct kp2000_device *pcard);
 
 extern struct file_operations  kp2000_fops;
 
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 7/8] staging: kpc2000: simplified kp2000_device retrieval in device attribute call-backs.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                             ` (4 preceding siblings ...)
  2019-05-20 19:52           ` [PATCH 6/8] staging: kpc2000: use IDA to assign card numbers Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH 8/8] staging: kpc2000: removed superfluous NULL checks from " Jeremy Sowden
                             ` (9 subsequent siblings)
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

All the call-backs used the same formula to retrieve the pcard from dev:

  struct pci_dev *pdev = to_pci_dev(dev);
  struct kp2000_device *pcard;

  if (!pdev)
    return NULL;

  pcard = pci_get_drvdata(pdev);

Since to_pci_dev is a wrapper for container_of, it will not return NULL,
and since pci_get_drvdata just calls dev_get_drvdata on the dev member
of pdev, this is equivalent to:

  struct kp2000_device *pcard = dev_get_drvdata(&(container_of(dev, struct pci_dev, dev)->dev));

and we can simplify it to:

  struct kp2000_device *pcard = dev_get_drvdata(dev);

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 28 +++++++++-----------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index a8383e8159eb..f6043ef7b55b 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -25,20 +25,10 @@ static DEFINE_IDA(card_num_ida);
  * SysFS Attributes
  ******************************************************/
 
-static struct kp2000_device *get_pcard(struct device *dev)
-{
-	struct pci_dev *pdev = to_pci_dev(dev);
-
-	if (!pdev)
-		return NULL;
-
-	return pci_get_drvdata(pdev);
-}
-
 static ssize_t ssid_show(struct device *dev, struct device_attribute *attr,
 			 char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -50,7 +40,7 @@ static DEVICE_ATTR_RO(ssid);
 static ssize_t ddna_show(struct device *dev, struct device_attribute *attr,
 			 char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -62,7 +52,7 @@ static DEVICE_ATTR_RO(ddna);
 static ssize_t card_id_show(struct device *dev, struct device_attribute *attr,
 			    char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -74,7 +64,7 @@ static DEVICE_ATTR_RO(card_id);
 static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr,
 			   char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -86,7 +76,7 @@ static DEVICE_ATTR_RO(hw_rev);
 static ssize_t build_show(struct device *dev, struct device_attribute *attr,
 			  char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -98,7 +88,7 @@ static DEVICE_ATTR_RO(build);
 static ssize_t build_date_show(struct device *dev,
 			       struct device_attribute *attr, char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -110,7 +100,7 @@ static DEVICE_ATTR_RO(build_date);
 static ssize_t build_time_show(struct device *dev,
 			       struct device_attribute *attr, char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -122,7 +112,7 @@ static DEVICE_ATTR_RO(build_time);
 static ssize_t cpld_reg_show(struct device *dev, struct device_attribute *attr,
 			     char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	u64 val;
 
 	if (!pcard)
@@ -137,7 +127,7 @@ static ssize_t cpld_reconfigure(struct device *dev,
 				struct device_attribute *attr,
 				const char *buf, size_t count)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	long wr_val;
 	int rv;
 
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 8/8] staging: kpc2000: removed superfluous NULL checks from device attribute call-backs.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                             ` (5 preceding siblings ...)
  2019-05-20 19:52           ` [PATCH 7/8] staging: kpc2000: simplified kp2000_device retrieval in device attribute call-backs Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH v4 0/8] staging: kpc2000: another batch of fixes Jeremy Sowden
                             ` (8 subsequent siblings)
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

All the attribute show call-backs check whether pcard is NULL.  However,
pci_set_drvdata(pdev, pcard) is called before the sysfs files are
created during probe, and pci_set_drvdata(pdev, NULL) is not called
until after they are destroyed during remove; therefore, pcard will not
be NULL, and we can drop the checks.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 27 --------------------------
 1 file changed, 27 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index f6043ef7b55b..4a0af2645747 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -30,9 +30,6 @@ static ssize_t ssid_show(struct device *dev, struct device_attribute *attr,
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-	if (!pcard)
-		return -ENXIO;
-
 	return sprintf(buf, "%016llx\n", pcard->ssid);
 }
 static DEVICE_ATTR_RO(ssid);
@@ -42,9 +39,6 @@ static ssize_t ddna_show(struct device *dev, struct device_attribute *attr,
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-	if (!pcard)
-		return -ENXIO;
-
 	return sprintf(buf, "%016llx\n", pcard->ddna);
 }
 static DEVICE_ATTR_RO(ddna);
@@ -54,9 +48,6 @@ static ssize_t card_id_show(struct device *dev, struct device_attribute *attr,
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-	if (!pcard)
-		return -ENXIO;
-
 	return sprintf(buf, "%08x\n", pcard->card_id);
 }
 static DEVICE_ATTR_RO(card_id);
@@ -66,9 +57,6 @@ static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr,
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-	if (!pcard)
-		return -ENXIO;
-
 	return sprintf(buf, "%08x\n", pcard->hardware_revision);
 }
 static DEVICE_ATTR_RO(hw_rev);
@@ -78,9 +66,6 @@ static ssize_t build_show(struct device *dev, struct device_attribute *attr,
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-	if (!pcard)
-		return -ENXIO;
-
 	return sprintf(buf, "%08x\n", pcard->build_version);
 }
 static DEVICE_ATTR_RO(build);
@@ -90,9 +75,6 @@ static ssize_t build_date_show(struct device *dev,
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-	if (!pcard)
-		return -ENXIO;
-
 	return sprintf(buf, "%08x\n", pcard->build_datestamp);
 }
 static DEVICE_ATTR_RO(build_date);
@@ -102,9 +84,6 @@ static ssize_t build_time_show(struct device *dev,
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-	if (!pcard)
-		return -ENXIO;
-
 	return sprintf(buf, "%08x\n", pcard->build_timestamp);
 }
 static DEVICE_ATTR_RO(build_time);
@@ -115,9 +94,6 @@ static ssize_t cpld_reg_show(struct device *dev, struct device_attribute *attr,
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	u64 val;
 
-	if (!pcard)
-		return -ENXIO;
-
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	return sprintf(buf, "%016llx\n", val);
 }
@@ -131,9 +107,6 @@ static ssize_t cpld_reconfigure(struct device *dev,
 	long wr_val;
 	int rv;
 
-	if (!pcard)
-		return -ENXIO;
-
 	rv = kstrtol(buf, 0, &wr_val);
 	if (rv < 0)
 		return rv;
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 0/8] staging: kpc2000: another batch of fixes
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                             ` (6 preceding siblings ...)
  2019-05-20 19:52           ` [PATCH 8/8] staging: kpc2000: removed superfluous NULL checks from " Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH v4 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                             ` (7 subsequent siblings)
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

There are a number relating to device attributes, one formatting patch,
and another that changes how card numbers are assigned.

Greg reckoned that the changes to the code in the attribute call-backs
that gets the struct kpc2000 object from the struct device object were
broken.  I've reviewed them and split them into two patches because I
was doing two different things in the previous patch.  I *think* they
are correct, but I've moved them to the end of the series in case I
really have just got the wrong end of the stick, so they can easily be
dropped.

Jeremy Sowden (8):
  staging: kpc2000: added separate show functions for kpc_uio_class
    device attributes, defined them as read-only and declared them
    static.
  staging: kpc2000: removed two kpc_uio_class device attributes.
  staging: kpc2000: improved formatting of core.c.
  staging: kpc2000: added a helper to get struct kp2000_device from
    struct device.
  staging: kpc2000: added separate show functions for readable kp device
    attributes, defined them as read-only, and declared them static.
  staging: kpc2000: use IDA to assign card numbers.
  staging: kpc2000: simplified kp2000_device retrieval in device
    attribute call-backs.
  staging: kpc2000: removed superfluous NULL checks from device
    attribute call-backs.

 drivers/staging/kpc2000/TODO                  |   1 -
 drivers/staging/kpc2000/kpc2000/cell_probe.c  | 123 ++-
 drivers/staging/kpc2000/kpc2000/core.c        | 859 ++++++++++--------
 .../staging/kpc2000/kpc2000/kp2000_module.c   |   1 +
 drivers/staging/kpc2000/kpc2000/pcie.h        |   9 +-
 5 files changed, 558 insertions(+), 435 deletions(-)

Since v3:

  * added the formatting patch for core.c and folded the kp device
    attribute formatting fixes into it;
  * added the patch that introduces get_pcard();
  * added missing clean-up of IDA and reworded the commit message;
  * split the patch that simplified the retrieval of struct
    kp2000_device from struct dev in the show call-backs into two, and
    moved them to the end of the series.

Since v2:

  * dropped the white-space patch since Greg has applied it;
  * added a reported-by tag to patch that drops two attributes;
  * merged the patches that declared attributes static with the ones
    that split up the show call-backs;
  * moved the attribute definitions next to their call-backs;
  * moved the patch that fixed the card-number race to the end of the
  * series;
  * use an IDA to fix the card-number race, not an atomic_t.

Since v1:

  * merged the DEVICE_ATTR_RO patches with the ones that split up the
    show call-backs;
  * converted the show call-backs to use sprintf, instead of scnprintf.

-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                             ` (7 preceding siblings ...)
  2019-05-20 19:52           ` [PATCH v4 0/8] staging: kpc2000: another batch of fixes Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH v4 2/8] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
                             ` (6 subsequent siblings)
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Defined separate simple show functions for each attribute instead of
having a one big one containing a chain of conditionals.

Replaced scnprintf calls with sprintf since all the outputs are short
bounded strings or single integers.

All of the device attributes are read-only, so used DEVICE_ATTR_RO to
define them.

The definitions are only used to populate the kpc_uio_class_attrs
attribute array, so declared them as static.

Fixes the following sparse warnings:

  drivers/staging/kpc2000/kpc2000/cell_probe.c:220:1: warning: symbol 'dev_attr_offset' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:221:1: warning: symbol 'dev_attr_size' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:222:1: warning: symbol 'dev_attr_type' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:223:1: warning: symbol 'dev_attr_s2c_dma' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:224:1: warning: symbol 'dev_attr_c2s_dma' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:225:1: warning: symbol 'dev_attr_irq_count' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:226:1: warning: symbol 'dev_attr_irq_base_num' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/cell_probe.c:227:1: warning: symbol 'dev_attr_core_num' was not declared. Should it be static?

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 135 ++++++++++++-------
 1 file changed, 89 insertions(+), 46 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index 6a2ebdf20113..3339b84b8666 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -145,55 +145,99 @@ struct kpc_uio_device {
     u16 core_num;
 };
 
-static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t offset_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
 {
-    struct kpc_uio_device *kudev = dev_get_drvdata(dev);
-
-    #define ATTR_NAME_CMP(v)  (strcmp(v, attr->attr.name) == 0)
-    if ATTR_NAME_CMP("offset"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.offset);
-    } else if ATTR_NAME_CMP("size"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.length);
-    } else if ATTR_NAME_CMP("type"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.type);
-    }
-    else if ATTR_NAME_CMP("s2c_dma"){
-        if (kudev->cte.s2c_dma_present){
-            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.s2c_dma_channel_num);
-        } else {
-            return scnprintf(buf, PAGE_SIZE, "not present\n");
-        }
-    } else if ATTR_NAME_CMP("c2s_dma"){
-        if (kudev->cte.c2s_dma_present){
-            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.c2s_dma_channel_num);
-        } else {
-            return scnprintf(buf, PAGE_SIZE, "not present\n");
-        }
-    }
-    else if ATTR_NAME_CMP("irq_count"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_count);
-    } else if ATTR_NAME_CMP("irq_base_num"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_base_num);
-    } else if ATTR_NAME_CMP("core_num"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->core_num);
-    } else {
-        return 0;
-    }
-    #undef ATTR_NAME_CMP
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.offset);
+}
+static DEVICE_ATTR_RO(offset);
+
+static ssize_t size_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.length);
 }
+static DEVICE_ATTR_RO(size);
 
+static ssize_t type_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.type);
+}
+static DEVICE_ATTR_RO(type);
+
+static ssize_t s2c_dma_ch_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	return 0;
+}
+static DEVICE_ATTR_RO(s2c_dma_ch);
+
+static ssize_t c2s_dma_ch_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	return 0;
+}
+static DEVICE_ATTR_RO(c2s_dma_ch);
+
+static ssize_t s2c_dma_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
 
-DEVICE_ATTR(offset,  0444, show_attr, NULL);
-DEVICE_ATTR(size,    0444, show_attr, NULL);
-DEVICE_ATTR(type,    0444, show_attr, NULL);
-DEVICE_ATTR(s2c_dma_ch, 0444, show_attr, NULL);
-DEVICE_ATTR(c2s_dma_ch, 0444, show_attr, NULL);
-DEVICE_ATTR(s2c_dma, 0444, show_attr, NULL);
-DEVICE_ATTR(c2s_dma, 0444, show_attr, NULL);
-DEVICE_ATTR(irq_count, 0444, show_attr, NULL);
-DEVICE_ATTR(irq_base_num, 0444, show_attr, NULL);
-DEVICE_ATTR(core_num, 0444, show_attr, NULL);
-struct attribute * kpc_uio_class_attrs[] = {
+	if (!kudev->cte.s2c_dma_present)
+		return sprintf(buf, "%s", "not present\n");
+
+	return sprintf(buf, "%u\n", kudev->cte.s2c_dma_channel_num);
+}
+static DEVICE_ATTR_RO(s2c_dma);
+
+static ssize_t c2s_dma_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	if (!kudev->cte.c2s_dma_present)
+		return sprintf(buf, "%s", "not present\n");
+
+	return sprintf(buf, "%u\n", kudev->cte.c2s_dma_channel_num);
+}
+static DEVICE_ATTR_RO(c2s_dma);
+
+static ssize_t irq_count_show(struct device *dev, struct device_attribute *attr,
+			      char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.irq_count);
+}
+static DEVICE_ATTR_RO(irq_count);
+
+static ssize_t irq_base_num_show(struct device *dev,
+				 struct device_attribute *attr, char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->cte.irq_base_num);
+}
+static DEVICE_ATTR_RO(irq_base_num);
+
+static ssize_t core_num_show(struct device *dev, struct device_attribute *attr,
+			     char *buf)
+{
+	struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", kudev->core_num);
+}
+static DEVICE_ATTR_RO(core_num);
+
+struct attribute *kpc_uio_class_attrs[] = {
 	&dev_attr_offset.attr,
 	&dev_attr_size.attr,
 	&dev_attr_type.attr,
@@ -207,7 +251,6 @@ struct attribute * kpc_uio_class_attrs[] = {
 	NULL,
 };
 
-
 static
 int  kp2000_check_uio_irq(struct kp2000_device *pcard, u32 irq_num)
 {
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 2/8] staging: kpc2000: removed two kpc_uio_class device attributes.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                             ` (8 preceding siblings ...)
  2019-05-20 19:52           ` [PATCH v4 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH v4 3/8] staging: kpc2000: improved formatting of core.c Jeremy Sowden
                             ` (5 subsequent siblings)
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

The show functions of two attributes output nothing and they are unused.
Removed them.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Reported-by: Matt Sickler <matt.sickler@daktronics.com>
---
 drivers/staging/kpc2000/kpc2000/cell_probe.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index 3339b84b8666..68d03f1d60f2 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -172,20 +172,6 @@ static ssize_t type_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(type);
 
-static ssize_t s2c_dma_ch_show(struct device *dev,
-			       struct device_attribute *attr, char *buf)
-{
-	return 0;
-}
-static DEVICE_ATTR_RO(s2c_dma_ch);
-
-static ssize_t c2s_dma_ch_show(struct device *dev,
-			       struct device_attribute *attr, char *buf)
-{
-	return 0;
-}
-static DEVICE_ATTR_RO(c2s_dma_ch);
-
 static ssize_t s2c_dma_show(struct device *dev, struct device_attribute *attr,
 			    char *buf)
 {
@@ -241,8 +227,6 @@ struct attribute *kpc_uio_class_attrs[] = {
 	&dev_attr_offset.attr,
 	&dev_attr_size.attr,
 	&dev_attr_type.attr,
-	&dev_attr_s2c_dma_ch.attr,
-	&dev_attr_c2s_dma_ch.attr,
 	&dev_attr_s2c_dma.attr,
 	&dev_attr_c2s_dma.attr,
 	&dev_attr_irq_count.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 3/8] staging: kpc2000: improved formatting of core.c.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                             ` (9 preceding siblings ...)
  2019-05-20 19:52           ` [PATCH v4 2/8] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH v4 4/8] staging: kpc2000: added a helper to get struct kp2000_device from struct device Jeremy Sowden
                             ` (4 subsequent siblings)
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

  * Indented with tabs.
  * Broke lines over 80 columns where possible.
  * Removed braces from one-statement blocks.
  * Tidied up some comments.
  * Removed multiple blank lines.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 810 ++++++++++++++-----------
 1 file changed, 445 insertions(+), 365 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index eb8bac62d33d..d4af5a643a7b 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -18,30 +18,52 @@
 #include <linux/jiffies.h>
 #include "pcie.h"
 
-
 /*******************************************************
-  * SysFS Attributes
-  ******************************************************/
-static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
+ * SysFS Attributes
+ ******************************************************/
+
+static ssize_t show_attr(struct device *dev, struct device_attribute *attr,
+			 char *buf)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
-    struct kp2000_device *pcard;
-
-    if (!pdev)  return -ENXIO;
-    pcard = pci_get_drvdata(pdev);
-    if (!pcard)  return -ENXIO;
-
-    if (strcmp("ssid", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);  } else
-    if (strcmp("ddna", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);  } else
-    if (strcmp("card_id", attr->attr.name) == 0){      return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);  } else
-    if (strcmp("hw_rev", attr->attr.name) == 0){       return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->hardware_revision);  } else
-    if (strcmp("build", attr->attr.name) == 0){        return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_version);  } else
-    if (strcmp("build_date", attr->attr.name) == 0){   return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_datestamp);  } else
-    if (strcmp("build_time", attr->attr.name) == 0){   return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_timestamp);  } else
-    { return -ENXIO; }
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct kp2000_device *pcard;
+
+	if (!pdev)
+		return -ENXIO;
+	pcard = pci_get_drvdata(pdev);
+	if (!pcard)
+		return -ENXIO;
+
+	if (strcmp("ssid", attr->attr.name) == 0)
+		return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);
+
+	if (strcmp("ddna", attr->attr.name) == 0)
+		return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);
+
+	if (strcmp("card_id", attr->attr.name) == 0)
+		return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);
+
+	if (strcmp("hw_rev", attr->attr.name) == 0)
+		return scnprintf(buf, PAGE_SIZE, "%08x\n",
+				 pcard->hardware_revision);
+
+	if (strcmp("build", attr->attr.name) == 0)
+		return scnprintf(buf, PAGE_SIZE, "%08x\n",
+				 pcard->build_version);
+
+	if (strcmp("build_date", attr->attr.name) == 0)
+		return scnprintf(buf, PAGE_SIZE, "%08x\n",
+				 pcard->build_datestamp);
+
+	if (strcmp("build_time", attr->attr.name) == 0)
+		return scnprintf(buf, PAGE_SIZE, "%08x\n",
+				 pcard->build_timestamp);
+
+	return -ENXIO;
 }
 
-static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t show_cpld_config_reg(struct device *dev,
+				    struct device_attribute *attr, char *buf)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
 	struct kp2000_device *pcard;
@@ -57,27 +79,33 @@ static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
 }
-static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+
+static ssize_t cpld_reconfigure(struct device *dev,
+				struct device_attribute *attr,
+				const char *buf, size_t count)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
-    long wr_val;
-    struct kp2000_device *pcard;
-    int rv;
-
-    if (!pdev)  return -ENXIO;
-    pcard = pci_get_drvdata(pdev);
-    if (!pcard)  return -ENXIO;
-
-    rv = kstrtol(buf, 0, &wr_val);
-    if (rv < 0)  return rv;
-    if (wr_val > 7)  return -EINVAL;
-
-    wr_val = wr_val << 8;
-    wr_val |= 0x1; // Set the "Configure Go" bit
-    writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
-    return count;
-}
+	struct pci_dev *pdev = to_pci_dev(dev);
+	long wr_val;
+	struct kp2000_device *pcard;
+	int rv;
 
+	if (!pdev)
+		return -ENXIO;
+	pcard = pci_get_drvdata(pdev);
+	if (!pcard)
+		return -ENXIO;
+
+	rv = kstrtol(buf, 0, &wr_val);
+	if (rv < 0)
+		return rv;
+	if (wr_val > 7)
+		return -EINVAL;
+
+	wr_val = wr_val << 8;
+	wr_val |= 0x1; // Set the "Configure Go" bit
+	writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
+	return count;
+}
 
 DEVICE_ATTR(ssid,       0444, show_attr, NULL);
 DEVICE_ATTR(ddna,       0444, show_attr, NULL);
@@ -89,349 +117,401 @@ DEVICE_ATTR(build_time, 0444, show_attr, NULL);
 DEVICE_ATTR(cpld_reg,   0444, show_cpld_config_reg, NULL);
 DEVICE_ATTR(cpld_reconfigure,   0220, NULL, cpld_reconfigure);
 
-static const struct attribute *  kp_attr_list[] = {
-    &dev_attr_ssid.attr,
-    &dev_attr_ddna.attr,
-    &dev_attr_card_id.attr,
-    &dev_attr_hw_rev.attr,
-    &dev_attr_build.attr,
-    &dev_attr_build_date.attr,
-    &dev_attr_build_time.attr,
-    &dev_attr_cpld_reg.attr,
-    &dev_attr_cpld_reconfigure.attr,
-    NULL,
+static const struct attribute *kp_attr_list[] = {
+	&dev_attr_ssid.attr,
+	&dev_attr_ddna.attr,
+	&dev_attr_card_id.attr,
+	&dev_attr_hw_rev.attr,
+	&dev_attr_build.attr,
+	&dev_attr_build_date.attr,
+	&dev_attr_build_time.attr,
+	&dev_attr_cpld_reg.attr,
+	&dev_attr_cpld_reconfigure.attr,
+	NULL,
 };
 
-
 /*******************************************************
-  * Functions
-  ******************************************************/
+ * Functions
+ ******************************************************/
 
 static void wait_and_read_ssid(struct kp2000_device *pcard)
 {
-    u64 read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
-    unsigned long timeout;
-
-    if (read_val & 0x8000000000000000){
-        pcard->ssid = read_val;
-        return;
-    }
-
-    timeout = jiffies + (HZ * 2);
-    do {
-        read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
-        if (read_val & 0x8000000000000000){
-            pcard->ssid = read_val;
-            return;
-        }
-        cpu_relax();
-        //schedule();
-    } while (time_before(jiffies, timeout));
-
-    dev_notice(&pcard->pdev->dev, "SSID didn't show up!\n");
-
-    #if 0
-    // Timed out waiting for the SSID to show up, just use the DDNA instead?
-    read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
-    pcard->ssid = read_val;
-    #else
-    // Timed out waiting for the SSID to show up, stick all zeros in the value
-    pcard->ssid = 0;
-    #endif
+	u64 read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
+	unsigned long timeout;
+
+	if (read_val & 0x8000000000000000) {
+		pcard->ssid = read_val;
+		return;
+	}
+
+	timeout = jiffies + (HZ * 2);
+	do {
+		read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
+		if (read_val & 0x8000000000000000) {
+			pcard->ssid = read_val;
+			return;
+		}
+		cpu_relax();
+		//schedule();
+	} while (time_before(jiffies, timeout));
+
+	dev_notice(&pcard->pdev->dev, "SSID didn't show up!\n");
+
+#if 0
+	// Timed out waiting for the SSID to show up, just use the DDNA instead?
+	read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
+	pcard->ssid = read_val;
+#else
+	// Timed out waiting for the SSID to show up, stick all zeros in the
+	// value
+	pcard->ssid = 0;
+#endif
 }
 
 static int  read_system_regs(struct kp2000_device *pcard)
 {
-    u64 read_val;
-
-    read_val = readq(pcard->sysinfo_regs_base + REG_MAGIC_NUMBER);
-    if (read_val != KP2000_MAGIC_VALUE){
-        dev_err(&pcard->pdev->dev, "Invalid magic!  Got: 0x%016llx  Want: 0x%016lx\n", read_val, KP2000_MAGIC_VALUE);
-        return -EILSEQ;
-    }
-
-    read_val = readq(pcard->sysinfo_regs_base + REG_CARD_ID_AND_BUILD);
-    pcard->card_id = (read_val & 0xFFFFFFFF00000000) >> 32;
-    pcard->build_version = (read_val & 0x00000000FFFFFFFF) >> 0;
-
-    read_val = readq(pcard->sysinfo_regs_base + REG_DATE_AND_TIME_STAMPS);
-    pcard->build_datestamp = (read_val & 0xFFFFFFFF00000000) >> 32;
-    pcard->build_timestamp = (read_val & 0x00000000FFFFFFFF) >> 0;
-
-    read_val = readq(pcard->sysinfo_regs_base + REG_CORE_TABLE_OFFSET);
-    pcard->core_table_length = (read_val & 0xFFFFFFFF00000000) >> 32;
-    pcard->core_table_offset = (read_val & 0x00000000FFFFFFFF) >> 0;
-
-    wait_and_read_ssid(pcard);
-
-    read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_HW_ID);
-    pcard->core_table_rev    = (read_val & 0x0000000000000F00) >> 8;
-    pcard->hardware_revision = (read_val & 0x000000000000001F);
-
-    read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
-    pcard->ddna = read_val;
-
-    dev_info(&pcard->pdev->dev, "system_regs: %08x %08x %08x %08x  %02x  %d %d  %016llx  %016llx\n",
-        pcard->card_id,
-        pcard->build_version,
-        pcard->build_datestamp,
-        pcard->build_timestamp,
-        pcard->hardware_revision,
-        pcard->core_table_rev,
-        pcard->core_table_length,
-        pcard->ssid,
-        pcard->ddna
-    );
-
-    if (pcard->core_table_rev > 1){
-        dev_err(&pcard->pdev->dev, "core table entry revision is higher than we can deal with, cannot continue with this card!\n");
-        return 1;
-    }
-
-    return 0;
+	u64 read_val;
+
+	read_val = readq(pcard->sysinfo_regs_base + REG_MAGIC_NUMBER);
+	if (read_val != KP2000_MAGIC_VALUE) {
+		dev_err(&pcard->pdev->dev,
+			"Invalid magic!  Got: 0x%016llx  Want: 0x%016lx\n",
+			read_val, KP2000_MAGIC_VALUE);
+		return -EILSEQ;
+	}
+
+	read_val = readq(pcard->sysinfo_regs_base + REG_CARD_ID_AND_BUILD);
+	pcard->card_id = (read_val & 0xFFFFFFFF00000000) >> 32;
+	pcard->build_version = (read_val & 0x00000000FFFFFFFF) >> 0;
+
+	read_val = readq(pcard->sysinfo_regs_base + REG_DATE_AND_TIME_STAMPS);
+	pcard->build_datestamp = (read_val & 0xFFFFFFFF00000000) >> 32;
+	pcard->build_timestamp = (read_val & 0x00000000FFFFFFFF) >> 0;
+
+	read_val = readq(pcard->sysinfo_regs_base + REG_CORE_TABLE_OFFSET);
+	pcard->core_table_length = (read_val & 0xFFFFFFFF00000000) >> 32;
+	pcard->core_table_offset = (read_val & 0x00000000FFFFFFFF) >> 0;
+
+	wait_and_read_ssid(pcard);
+
+	read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_HW_ID);
+	pcard->core_table_rev    = (read_val & 0x0000000000000F00) >> 8;
+	pcard->hardware_revision = (read_val & 0x000000000000001F);
+
+	read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
+	pcard->ddna = read_val;
+
+	dev_info(&pcard->pdev->dev,
+		 "system_regs: %08x %08x %08x %08x  %02x  %d %d  %016llx  %016llx\n",
+		 pcard->card_id,
+		 pcard->build_version,
+		 pcard->build_datestamp,
+		 pcard->build_timestamp,
+		 pcard->hardware_revision,
+		 pcard->core_table_rev,
+		 pcard->core_table_length,
+		 pcard->ssid,
+		 pcard->ddna);
+
+	if (pcard->core_table_rev > 1) {
+		dev_err(&pcard->pdev->dev,
+			"core table entry revision is higher than we can deal with, cannot continue with this card!\n");
+		return 1;
+	}
+
+	return 0;
 }
 
-irqreturn_t  kp2000_irq_handler(int irq, void *dev_id)
+irqreturn_t kp2000_irq_handler(int irq, void *dev_id)
 {
-    struct kp2000_device  *pcard = (struct kp2000_device*)dev_id;
-    SetBackEndControl(pcard->dma_common_regs, KPC_DMA_CARD_IRQ_ENABLE | KPC_DMA_CARD_USER_INTERRUPT_MODE | KPC_DMA_CARD_USER_INTERRUPT_ACTIVE);
-    return IRQ_HANDLED;
+	struct kp2000_device *pcard = (struct kp2000_device *)dev_id;
+
+	SetBackEndControl(pcard->dma_common_regs,
+			  KPC_DMA_CARD_IRQ_ENABLE |
+			  KPC_DMA_CARD_USER_INTERRUPT_MODE |
+			  KPC_DMA_CARD_USER_INTERRUPT_ACTIVE);
+	return IRQ_HANDLED;
 }
 
-int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+int kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
-    int err = 0;
-    struct kp2000_device *pcard;
-    static int card_count = 1;
-    int rv;
-    unsigned long reg_bar_phys_addr;
-    unsigned long reg_bar_phys_len;
-    unsigned long dma_bar_phys_addr;
-    unsigned long dma_bar_phys_len;
-    u16 regval;
-
-    dev_dbg(&pdev->dev, "kp2000_pcie_probe(pdev = [%p], id = [%p])\n", pdev, id);
-
-    //{ Step 1: Allocate a struct for the pcard
-    pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);
-    if (NULL == pcard){
-        dev_err(&pdev->dev, "probe: failed to allocate private card data\n");
-        return -ENOMEM;
-    }
-    dev_dbg(&pdev->dev, "probe: allocated struct kp2000_device @ %p\n", pcard);
-    //}
-
-    //{ Step 2: Initialize trivial pcard elements
-    pcard->card_num = card_count;
-    card_count++;
-    scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
-
-    mutex_init(&pcard->sem);
-    lock_card(pcard);
-
-    pcard->pdev = pdev;
-    pci_set_drvdata(pdev, pcard);
-    //}
-
-    //{ Step 3: Enable PCI device
-    err = pci_enable_device(pcard->pdev);
-    if (err){
-        dev_err(&pcard->pdev->dev, "probe: failed to enable PCIE2000 PCIe device (%d)\n", err);
-        goto out3;
-    }
-    //}
-
-    //{ Step 4: Setup the Register BAR
-    reg_bar_phys_addr = pci_resource_start(pcard->pdev, REG_BAR);
-    reg_bar_phys_len = pci_resource_len(pcard->pdev, REG_BAR);
-
-    pcard->regs_bar_base = ioremap_nocache(reg_bar_phys_addr, PAGE_SIZE);
-    if (NULL == pcard->regs_bar_base){
-        dev_err(&pcard->pdev->dev, "probe: REG_BAR could not remap memory to virtual space\n");
-        err = -ENODEV;
-        goto out4;
-    }
-    dev_dbg(&pcard->pdev->dev, "probe: REG_BAR virt hardware address start [%p]\n", pcard->regs_bar_base);
-
-    err = pci_request_region(pcard->pdev, REG_BAR, KP_DRIVER_NAME_KP2000);
-    if (err){
-        iounmap(pcard->regs_bar_base);
-        dev_err(&pcard->pdev->dev, "probe: failed to acquire PCI region (%d)\n", err);
-        err = -ENODEV;
-        goto out4;
-    }
-
-    pcard->regs_base_resource.start = reg_bar_phys_addr;
-    pcard->regs_base_resource.end   = reg_bar_phys_addr + reg_bar_phys_len - 1;
-    pcard->regs_base_resource.flags = IORESOURCE_MEM;
-    //}
-
-    //{ Step 5: Setup the DMA BAR
-    dma_bar_phys_addr = pci_resource_start(pcard->pdev, DMA_BAR);
-    dma_bar_phys_len = pci_resource_len(pcard->pdev, DMA_BAR);
-
-    pcard->dma_bar_base = ioremap_nocache(dma_bar_phys_addr, dma_bar_phys_len);
-    if (NULL == pcard->dma_bar_base){
-        dev_err(&pcard->pdev->dev, "probe: DMA_BAR could not remap memory to virtual space\n");
-        err = -ENODEV;
-        goto out5;
-    }
-    dev_dbg(&pcard->pdev->dev, "probe: DMA_BAR virt hardware address start [%p]\n", pcard->dma_bar_base);
-
-    pcard->dma_common_regs = pcard->dma_bar_base + KPC_DMA_COMMON_OFFSET;
-
-    err = pci_request_region(pcard->pdev, DMA_BAR, "kp2000_pcie");
-    if (err){
-        iounmap(pcard->dma_bar_base);
-        dev_err(&pcard->pdev->dev, "probe: failed to acquire PCI region (%d)\n", err);
-        err = -ENODEV;
-        goto out5;
-    }
-
-    pcard->dma_base_resource.start = dma_bar_phys_addr;
-    pcard->dma_base_resource.end   = dma_bar_phys_addr + dma_bar_phys_len - 1;
-    pcard->dma_base_resource.flags = IORESOURCE_MEM;
-    //}
-
-    //{ Step 6: System Regs
-    pcard->sysinfo_regs_base = pcard->regs_bar_base;
-    err = read_system_regs(pcard);
-    if (err)
-        goto out6;
-
-    // Disable all "user" interrupts because they're not used yet.
-    writeq(0xFFFFFFFFFFFFFFFF, pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
-    //}
-
-    //{ Step 7: Configure PCI thingies
-    // let the card master PCIe
-    pci_set_master(pcard->pdev);
-    // enable IO and mem if not already done
-    pci_read_config_word(pcard->pdev, PCI_COMMAND, &regval);
-    regval |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
-    pci_write_config_word(pcard->pdev, PCI_COMMAND, regval);
-
-    // Clear relaxed ordering bit
-    pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN, 0);
-
-    // Set Max_Payload_Size and Max_Read_Request_Size
-    regval = (0x0) << 5; // Max_Payload_Size = 128 B
-    pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_PAYLOAD, regval);
-    regval = (0x0) << 12; // Max_Read_Request_Size = 128 B
-    pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_READRQ, regval);
-
-    // Enable error reporting for: Correctable Errors, Non-Fatal Errors, Fatal Errors, Unsupported Requests
-    pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, 0, PCI_EXP_DEVCTL_CERE | PCI_EXP_DEVCTL_NFERE | PCI_EXP_DEVCTL_FERE | PCI_EXP_DEVCTL_URRE);
-
-    err = dma_set_mask(PCARD_TO_DEV(pcard), DMA_BIT_MASK(64));
-    if (err){
-        dev_err(&pcard->pdev->dev, "CANNOT use DMA mask %0llx\n", DMA_BIT_MASK(64));
-        goto out7;
-    }
-    dev_dbg(&pcard->pdev->dev, "Using DMA mask %0llx\n", dma_get_mask(PCARD_TO_DEV(pcard)));
-    //}
-
-    //{ Step 8: Configure IRQs
-    err = pci_enable_msi(pcard->pdev);
-    if (err < 0)
-        goto out8a;
-
-    rv = request_irq(pcard->pdev->irq, kp2000_irq_handler, IRQF_SHARED, pcard->name, pcard);
-    if (rv){
-        dev_err(&pcard->pdev->dev, "kp2000_pcie_probe: failed to request_irq: %d\n", rv);
-        goto out8b;
-    }
-    //}
-
-    //{ Step 9: Setup sysfs attributes
-    err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);
-    if (err){
-        dev_err(&pdev->dev, "Failed to add sysfs files: %d\n", err);
-        goto out9;
-    }
-    //}
-
-    //{ Step 10: Setup misc device
-    pcard->miscdev.minor = MISC_DYNAMIC_MINOR;
-    pcard->miscdev.fops = &kp2000_fops;
-    pcard->miscdev.parent = &pcard->pdev->dev;
-    pcard->miscdev.name = pcard->name;
-
-    err = misc_register(&pcard->miscdev);
-    if (err){
-        dev_err(&pcard->pdev->dev, "kp2000_pcie_probe: misc_register failed: %d\n", err);
-        goto out10;
-    }
-    //}
-
-    //{ Step 11: Probe cores
-    err = kp2000_probe_cores(pcard);
-    if (err)
-        goto out11;
-    //}
-
-    //{ Step 12: Enable IRQs in HW
-    SetBackEndControl(pcard->dma_common_regs, KPC_DMA_CARD_IRQ_ENABLE | KPC_DMA_CARD_USER_INTERRUPT_MODE);
-    //}
-
-    dev_dbg(&pcard->pdev->dev, "kp2000_pcie_probe() complete!\n");
-    unlock_card(pcard);
-    return 0;
-
-  out11:
-    misc_deregister(&pcard->miscdev);
-  out10:
-    sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
-  out9:
-    free_irq(pcard->pdev->irq, pcard);
-  out8b:
-    pci_disable_msi(pcard->pdev);
-  out8a:
-  out7:
-  out6:
-    iounmap(pcard->dma_bar_base);
-    pci_release_region(pdev, DMA_BAR);
-    pcard->dma_bar_base = NULL;
-  out5:
-    iounmap(pcard->regs_bar_base);
-    pci_release_region(pdev, REG_BAR);
-    pcard->regs_bar_base = NULL;
-  out4:
-    pci_disable_device(pcard->pdev);
-  out3:
-    unlock_card(pcard);
-    kfree(pcard);
-    return err;
+	int err = 0;
+	struct kp2000_device *pcard;
+	static int card_count = 1;
+	int rv;
+	unsigned long reg_bar_phys_addr;
+	unsigned long reg_bar_phys_len;
+	unsigned long dma_bar_phys_addr;
+	unsigned long dma_bar_phys_len;
+	u16 regval;
+
+	dev_dbg(&pdev->dev, "kp2000_pcie_probe(pdev = [%p], id = [%p])\n",
+		pdev, id);
+
+	/*
+	 * Step 1: Allocate a struct for the pcard
+	 */
+	pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);
+	if (NULL == pcard) {
+		dev_err(&pdev->dev,
+			"probe: failed to allocate private card data\n");
+		return -ENOMEM;
+	}
+	dev_dbg(&pdev->dev, "probe: allocated struct kp2000_device @ %p\n",
+		pcard);
+
+	/*
+	 * Step 2: Initialize trivial pcard elements
+	 */
+	pcard->card_num = card_count;
+	card_count++;
+	scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
+
+	mutex_init(&pcard->sem);
+	lock_card(pcard);
+
+	pcard->pdev = pdev;
+	pci_set_drvdata(pdev, pcard);
+
+	/*
+	 * Step 3: Enable PCI device
+	 */
+	err = pci_enable_device(pcard->pdev);
+	if (err) {
+		dev_err(&pcard->pdev->dev,
+			"probe: failed to enable PCIE2000 PCIe device (%d)\n",
+			err);
+		goto out3;
+	}
+
+	/*
+	 * Step 4: Setup the Register BAR
+	 */
+	reg_bar_phys_addr = pci_resource_start(pcard->pdev, REG_BAR);
+	reg_bar_phys_len = pci_resource_len(pcard->pdev, REG_BAR);
+
+	pcard->regs_bar_base = ioremap_nocache(reg_bar_phys_addr, PAGE_SIZE);
+	if (NULL == pcard->regs_bar_base) {
+		dev_err(&pcard->pdev->dev,
+			"probe: REG_BAR could not remap memory to virtual space\n");
+		err = -ENODEV;
+		goto out4;
+	}
+	dev_dbg(&pcard->pdev->dev,
+		"probe: REG_BAR virt hardware address start [%p]\n",
+		pcard->regs_bar_base);
+
+	err = pci_request_region(pcard->pdev, REG_BAR, KP_DRIVER_NAME_KP2000);
+	if (err) {
+		iounmap(pcard->regs_bar_base);
+		dev_err(&pcard->pdev->dev,
+			"probe: failed to acquire PCI region (%d)\n",
+			err);
+		err = -ENODEV;
+		goto out4;
+	}
+
+	pcard->regs_base_resource.start = reg_bar_phys_addr;
+	pcard->regs_base_resource.end   = reg_bar_phys_addr +
+					  reg_bar_phys_len - 1;
+	pcard->regs_base_resource.flags = IORESOURCE_MEM;
+
+	/*
+	 * Step 5: Setup the DMA BAR
+	 */
+	dma_bar_phys_addr = pci_resource_start(pcard->pdev, DMA_BAR);
+	dma_bar_phys_len = pci_resource_len(pcard->pdev, DMA_BAR);
+
+	pcard->dma_bar_base = ioremap_nocache(dma_bar_phys_addr,
+					      dma_bar_phys_len);
+	if (NULL == pcard->dma_bar_base) {
+		dev_err(&pcard->pdev->dev,
+			"probe: DMA_BAR could not remap memory to virtual space\n");
+		err = -ENODEV;
+		goto out5;
+	}
+	dev_dbg(&pcard->pdev->dev,
+		"probe: DMA_BAR virt hardware address start [%p]\n",
+		pcard->dma_bar_base);
+
+	pcard->dma_common_regs = pcard->dma_bar_base + KPC_DMA_COMMON_OFFSET;
+
+	err = pci_request_region(pcard->pdev, DMA_BAR, "kp2000_pcie");
+	if (err) {
+		iounmap(pcard->dma_bar_base);
+		dev_err(&pcard->pdev->dev,
+			"probe: failed to acquire PCI region (%d)\n", err);
+		err = -ENODEV;
+		goto out5;
+	}
+
+	pcard->dma_base_resource.start = dma_bar_phys_addr;
+	pcard->dma_base_resource.end   = dma_bar_phys_addr +
+					 dma_bar_phys_len - 1;
+	pcard->dma_base_resource.flags = IORESOURCE_MEM;
+
+	/*
+	 * Step 6: System Regs
+	 */
+	pcard->sysinfo_regs_base = pcard->regs_bar_base;
+	err = read_system_regs(pcard);
+	if (err)
+		goto out6;
+
+	// Disable all "user" interrupts because they're not used yet.
+	writeq(0xFFFFFFFFFFFFFFFF,
+	       pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
+
+	/*
+	 * Step 7: Configure PCI thingies
+	 */
+	// let the card master PCIe
+	pci_set_master(pcard->pdev);
+	// enable IO and mem if not already done
+	pci_read_config_word(pcard->pdev, PCI_COMMAND, &regval);
+	regval |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
+	pci_write_config_word(pcard->pdev, PCI_COMMAND, regval);
+
+	// Clear relaxed ordering bit
+	pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL,
+					   PCI_EXP_DEVCTL_RELAX_EN, 0);
+
+	// Set Max_Payload_Size and Max_Read_Request_Size
+	regval = (0x0) << 5; // Max_Payload_Size = 128 B
+	pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL,
+					   PCI_EXP_DEVCTL_PAYLOAD, regval);
+	regval = (0x0) << 12; // Max_Read_Request_Size = 128 B
+	pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL,
+					   PCI_EXP_DEVCTL_READRQ, regval);
+
+	// Enable error reporting for: Correctable Errors, Non-Fatal Errors,
+	// Fatal Errors, Unsupported Requests
+	pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, 0,
+					   PCI_EXP_DEVCTL_CERE |
+					   PCI_EXP_DEVCTL_NFERE |
+					   PCI_EXP_DEVCTL_FERE |
+					   PCI_EXP_DEVCTL_URRE);
+
+	err = dma_set_mask(PCARD_TO_DEV(pcard), DMA_BIT_MASK(64));
+	if (err) {
+		dev_err(&pcard->pdev->dev,
+			"CANNOT use DMA mask %0llx\n", DMA_BIT_MASK(64));
+		goto out7;
+	}
+	dev_dbg(&pcard->pdev->dev,
+		"Using DMA mask %0llx\n", dma_get_mask(PCARD_TO_DEV(pcard)));
+
+	/*
+	 * Step 8: Configure IRQs
+	 */
+	err = pci_enable_msi(pcard->pdev);
+	if (err < 0)
+		goto out8a;
+
+	rv = request_irq(pcard->pdev->irq, kp2000_irq_handler, IRQF_SHARED,
+			 pcard->name, pcard);
+	if (rv) {
+		dev_err(&pcard->pdev->dev,
+			"kp2000_pcie_probe: failed to request_irq: %d\n", rv);
+		goto out8b;
+	}
+
+	/*
+	 * Step 9: Setup sysfs attributes
+	 */
+	err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);
+	if (err) {
+		dev_err(&pdev->dev, "Failed to add sysfs files: %d\n", err);
+		goto out9;
+	}
+
+	/*
+	 * Step 10: Setup misc device
+	 */
+	pcard->miscdev.minor = MISC_DYNAMIC_MINOR;
+	pcard->miscdev.fops = &kp2000_fops;
+	pcard->miscdev.parent = &pcard->pdev->dev;
+	pcard->miscdev.name = pcard->name;
+
+	err = misc_register(&pcard->miscdev);
+	if (err) {
+		dev_err(&pcard->pdev->dev,
+			"kp2000_pcie_probe: misc_register failed: %d\n", err);
+		goto out10;
+	}
+
+	/*
+	 * Step 11: Probe cores
+	 */
+	err = kp2000_probe_cores(pcard);
+	if (err)
+		goto out11;
+
+	/*
+	 * Step 12: Enable IRQs in HW
+	 */
+	SetBackEndControl(pcard->dma_common_regs,
+			  KPC_DMA_CARD_IRQ_ENABLE |
+			  KPC_DMA_CARD_USER_INTERRUPT_MODE);
+
+	dev_dbg(&pcard->pdev->dev, "kp2000_pcie_probe() complete!\n");
+	unlock_card(pcard);
+	return 0;
+
+out11:
+	misc_deregister(&pcard->miscdev);
+out10:
+	sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
+out9:
+	free_irq(pcard->pdev->irq, pcard);
+out8b:
+	pci_disable_msi(pcard->pdev);
+out8a:
+out7:
+out6:
+	iounmap(pcard->dma_bar_base);
+	pci_release_region(pdev, DMA_BAR);
+	pcard->dma_bar_base = NULL;
+out5:
+	iounmap(pcard->regs_bar_base);
+	pci_release_region(pdev, REG_BAR);
+	pcard->regs_bar_base = NULL;
+out4:
+	pci_disable_device(pcard->pdev);
+out3:
+	unlock_card(pcard);
+	kfree(pcard);
+	return err;
 }
 
-
-void  kp2000_pcie_remove(struct pci_dev *pdev)
+void kp2000_pcie_remove(struct pci_dev *pdev)
 {
-    struct kp2000_device *pcard = pci_get_drvdata(pdev);
-
-    dev_dbg(&pdev->dev, "kp2000_pcie_remove(pdev=%p)\n", pdev);
-
-    if (pcard == NULL)  return;
-
-    lock_card(pcard);
-    kp2000_remove_cores(pcard);
-    mfd_remove_devices(PCARD_TO_DEV(pcard));
-    misc_deregister(&pcard->miscdev);
-    sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
-    free_irq(pcard->pdev->irq, pcard);
-    pci_disable_msi(pcard->pdev);
-    if (pcard->dma_bar_base != NULL){
-        iounmap(pcard->dma_bar_base);
-        pci_release_region(pdev, DMA_BAR);
-        pcard->dma_bar_base = NULL;
-    }
-    if (pcard->regs_bar_base != NULL){
-        iounmap(pcard->regs_bar_base);
-        pci_release_region(pdev, REG_BAR);
-        pcard->regs_bar_base = NULL;
-    }
-    pci_disable_device(pcard->pdev);
-    pci_set_drvdata(pdev, NULL);
-    unlock_card(pcard);
-    kfree(pcard);
+	struct kp2000_device *pcard = pci_get_drvdata(pdev);
+
+	dev_dbg(&pdev->dev, "kp2000_pcie_remove(pdev=%p)\n", pdev);
+
+	if (pcard == NULL)
+		return;
+
+	lock_card(pcard);
+	kp2000_remove_cores(pcard);
+	mfd_remove_devices(PCARD_TO_DEV(pcard));
+	misc_deregister(&pcard->miscdev);
+	sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
+	free_irq(pcard->pdev->irq, pcard);
+	pci_disable_msi(pcard->pdev);
+	if (pcard->dma_bar_base != NULL) {
+		iounmap(pcard->dma_bar_base);
+		pci_release_region(pdev, DMA_BAR);
+		pcard->dma_bar_base = NULL;
+	}
+	if (pcard->regs_bar_base != NULL) {
+		iounmap(pcard->regs_bar_base);
+		pci_release_region(pdev, REG_BAR);
+		pcard->regs_bar_base = NULL;
+	}
+	pci_disable_device(pcard->pdev);
+	pci_set_drvdata(pdev, NULL);
+	unlock_card(pcard);
+	kfree(pcard);
 }
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 4/8] staging: kpc2000: added a helper to get struct kp2000_device from struct device.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                             ` (10 preceding siblings ...)
  2019-05-20 19:52           ` [PATCH v4 3/8] staging: kpc2000: improved formatting of core.c Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH v4 5/8] staging: kpc2000: added separate show functions for readable kp device attributes, defined them as read-only, and declared them static Jeremy Sowden
                             ` (3 subsequent siblings)
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

The attribute call-backs all use the same code to get the pcard from dev:

  struct pci_dev *pdev = to_pci_dev(dev);
  struct kp2000_device *pcard;

  if (!pdev)
    return -ENXIO;
  pcard = pci_get_drvdata(pdev);
  if (!pcard)
    return -ENXIO;

Added a function to reduce the duplicated code.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 29 ++++++++++++--------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index d4af5a643a7b..c33595cc1332 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -22,15 +22,21 @@
  * SysFS Attributes
  ******************************************************/
 
-static ssize_t show_attr(struct device *dev, struct device_attribute *attr,
-			 char *buf)
+static struct kp2000_device *get_pcard(struct device *dev)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
-	struct kp2000_device *pcard;
 
 	if (!pdev)
-		return -ENXIO;
-	pcard = pci_get_drvdata(pdev);
+		return NULL;
+
+	return pci_get_drvdata(pdev);
+}
+
+static ssize_t show_attr(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kp2000_device *pcard = get_pcard(dev);
+
 	if (!pcard)
 		return -ENXIO;
 
@@ -65,14 +71,9 @@ static ssize_t show_attr(struct device *dev, struct device_attribute *attr,
 static ssize_t show_cpld_config_reg(struct device *dev,
 				    struct device_attribute *attr, char *buf)
 {
-	struct pci_dev *pdev = to_pci_dev(dev);
-	struct kp2000_device *pcard;
+	struct kp2000_device *pcard = get_pcard(dev);
 	u64 val;
 
-	if (!pdev)
-		return -ENXIO;
-
-	pcard = pci_get_drvdata(pdev);
 	if (!pcard)
 		return -ENXIO;
 
@@ -84,14 +85,10 @@ static ssize_t cpld_reconfigure(struct device *dev,
 				struct device_attribute *attr,
 				const char *buf, size_t count)
 {
-	struct pci_dev *pdev = to_pci_dev(dev);
+	struct kp2000_device *pcard = get_pcard(dev);
 	long wr_val;
-	struct kp2000_device *pcard;
 	int rv;
 
-	if (!pdev)
-		return -ENXIO;
-	pcard = pci_get_drvdata(pdev);
 	if (!pcard)
 		return -ENXIO;
 
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 5/8] staging: kpc2000: added separate show functions for readable kp device attributes, defined them as read-only, and declared them static.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                             ` (11 preceding siblings ...)
  2019-05-20 19:52           ` [PATCH v4 4/8] staging: kpc2000: added a helper to get struct kp2000_device from struct device Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH v4 6/8] staging: kpc2000: use IDA to assign card numbers Jeremy Sowden
                             ` (2 subsequent siblings)
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Defineed separate simple show functions for each attribute instead of
having a one big one containing a chain of conditionals.

Replaced calls to scnprintf with sprintf since all the outputs are
single integers.

All the readable device attributes are read-only, so used DEVICE_ATTR_RO
to define them.

The definitions are only used to populate the kp_attr_list attribute
array, so declared them as static.

Fixes the following sparse warnings:

  drivers/staging/kpc2000/kpc2000/core.c:152:1: warning: symbol 'dev_attr_ssid' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:153:1: warning: symbol 'dev_attr_ddna' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:154:1: warning: symbol 'dev_attr_card_id' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:155:1: warning: symbol 'dev_attr_hw_rev' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:156:1: warning: symbol 'dev_attr_build' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:157:1: warning: symbol 'dev_attr_build_date' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:158:1: warning: symbol 'dev_attr_build_time' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:159:1: warning: symbol 'dev_attr_cpld_reg' was not declared. Should it be static?
  drivers/staging/kpc2000/kpc2000/core.c:161:1: warning: symbol 'dev_attr_cpld_reconfigure' was not declared. Should it be static?

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 106 +++++++++++++++++--------
 1 file changed, 73 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index c33595cc1332..38de7e7a824d 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -32,7 +32,7 @@ static struct kp2000_device *get_pcard(struct device *dev)
 	return pci_get_drvdata(pdev);
 }
 
-static ssize_t show_attr(struct device *dev, struct device_attribute *attr,
+static ssize_t ssid_show(struct device *dev, struct device_attribute *attr,
 			 char *buf)
 {
 	struct kp2000_device *pcard = get_pcard(dev);
@@ -40,36 +40,84 @@ static ssize_t show_attr(struct device *dev, struct device_attribute *attr,
 	if (!pcard)
 		return -ENXIO;
 
-	if (strcmp("ssid", attr->attr.name) == 0)
-		return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);
+	return sprintf(buf, "%016llx\n", pcard->ssid);
+}
+static DEVICE_ATTR_RO(ssid);
 
-	if (strcmp("ddna", attr->attr.name) == 0)
-		return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);
+static ssize_t ddna_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kp2000_device *pcard = get_pcard(dev);
 
-	if (strcmp("card_id", attr->attr.name) == 0)
-		return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);
+	if (!pcard)
+		return -ENXIO;
+
+	return sprintf(buf, "%016llx\n", pcard->ddna);
+}
+static DEVICE_ATTR_RO(ddna);
+
+static ssize_t card_id_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kp2000_device *pcard = get_pcard(dev);
 
-	if (strcmp("hw_rev", attr->attr.name) == 0)
-		return scnprintf(buf, PAGE_SIZE, "%08x\n",
-				 pcard->hardware_revision);
+	if (!pcard)
+		return -ENXIO;
 
-	if (strcmp("build", attr->attr.name) == 0)
-		return scnprintf(buf, PAGE_SIZE, "%08x\n",
-				 pcard->build_version);
+	return sprintf(buf, "%08x\n", pcard->card_id);
+}
+static DEVICE_ATTR_RO(card_id);
 
-	if (strcmp("build_date", attr->attr.name) == 0)
-		return scnprintf(buf, PAGE_SIZE, "%08x\n",
-				 pcard->build_datestamp);
+static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
+{
+	struct kp2000_device *pcard = get_pcard(dev);
 
-	if (strcmp("build_time", attr->attr.name) == 0)
-		return scnprintf(buf, PAGE_SIZE, "%08x\n",
-				 pcard->build_timestamp);
+	if (!pcard)
+		return -ENXIO;
 
-	return -ENXIO;
+	return sprintf(buf, "%08x\n", pcard->hardware_revision);
 }
+static DEVICE_ATTR_RO(hw_rev);
 
-static ssize_t show_cpld_config_reg(struct device *dev,
-				    struct device_attribute *attr, char *buf)
+static ssize_t build_show(struct device *dev, struct device_attribute *attr,
+			  char *buf)
+{
+	struct kp2000_device *pcard = get_pcard(dev);
+
+	if (!pcard)
+		return -ENXIO;
+
+	return sprintf(buf, "%08x\n", pcard->build_version);
+}
+static DEVICE_ATTR_RO(build);
+
+static ssize_t build_date_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct kp2000_device *pcard = get_pcard(dev);
+
+	if (!pcard)
+		return -ENXIO;
+
+	return sprintf(buf, "%08x\n", pcard->build_datestamp);
+}
+static DEVICE_ATTR_RO(build_date);
+
+static ssize_t build_time_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct kp2000_device *pcard = get_pcard(dev);
+
+	if (!pcard)
+		return -ENXIO;
+
+	return sprintf(buf, "%08x\n", pcard->build_timestamp);
+}
+static DEVICE_ATTR_RO(build_time);
+
+static ssize_t cpld_reg_show(struct device *dev, struct device_attribute *attr,
+			     char *buf)
 {
 	struct kp2000_device *pcard = get_pcard(dev);
 	u64 val;
@@ -78,8 +126,9 @@ static ssize_t show_cpld_config_reg(struct device *dev,
 		return -ENXIO;
 
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
-	return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
+	return sprintf(buf, "%016llx\n", val);
 }
+static DEVICE_ATTR_RO(cpld_reg);
 
 static ssize_t cpld_reconfigure(struct device *dev,
 				struct device_attribute *attr,
@@ -103,16 +152,7 @@ static ssize_t cpld_reconfigure(struct device *dev,
 	writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	return count;
 }
-
-DEVICE_ATTR(ssid,       0444, show_attr, NULL);
-DEVICE_ATTR(ddna,       0444, show_attr, NULL);
-DEVICE_ATTR(card_id,    0444, show_attr, NULL);
-DEVICE_ATTR(hw_rev,     0444, show_attr, NULL);
-DEVICE_ATTR(build,      0444, show_attr, NULL);
-DEVICE_ATTR(build_date, 0444, show_attr, NULL);
-DEVICE_ATTR(build_time, 0444, show_attr, NULL);
-DEVICE_ATTR(cpld_reg,   0444, show_cpld_config_reg, NULL);
-DEVICE_ATTR(cpld_reconfigure,   0220, NULL, cpld_reconfigure);
+static DEVICE_ATTR(cpld_reconfigure, 0220, NULL, cpld_reconfigure);
 
 static const struct attribute *kp_attr_list[] = {
 	&dev_attr_ssid.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 6/8] staging: kpc2000: use IDA to assign card numbers.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                             ` (12 preceding siblings ...)
  2019-05-20 19:52           ` [PATCH v4 5/8] staging: kpc2000: added separate show functions for readable kp device attributes, defined them as read-only, and declared them static Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH v4 7/8] staging: kpc2000: simplified kp2000_device retrieval in device attribute call-backs Jeremy Sowden
  2019-05-20 19:52           ` [PATCH v4 8/8] staging: kpc2000: removed superfluous NULL checks from " Jeremy Sowden
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

Previously the next card number was assigned from a static int local
variable.  Replaced it with an IDA.  Avoids the assignment of ever-
increasing card-numbers by allowing them to be reused.

Updated TODO.

Corrected format-specifier for unsigned pcard->card_num.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/TODO                  |  1 -
 drivers/staging/kpc2000/kpc2000/core.c        | 23 +++++++++++++++----
 .../staging/kpc2000/kpc2000/kp2000_module.c   |  1 +
 drivers/staging/kpc2000/kpc2000/pcie.h        |  9 ++++----
 4 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/kpc2000/TODO b/drivers/staging/kpc2000/TODO
index 669fe5bf9637..47530e23e940 100644
--- a/drivers/staging/kpc2000/TODO
+++ b/drivers/staging/kpc2000/TODO
@@ -1,6 +1,5 @@
 - the kpc_spi driver doesn't seem to let multiple transactions (to different instances of the core) happen in parallel...
 - The kpc_i2c driver is a hot mess, it should probably be cleaned up a ton.  It functions against current hardware though.
-- pcard->card_num in kp2000_pcie_probe() is a global variable and needs atomic / locking / something better.
 - would be nice if the AIO fileops in kpc_dma could be made to work
     - probably want to add a CONFIG_ option to control compilation of the AIO functions
 - if the AIO fileops in kpc_dma start working, next would be making iov_count > 1 work too
diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index 38de7e7a824d..a8383e8159eb 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0+
+#include <linux/idr.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/pci.h>
@@ -18,6 +19,8 @@
 #include <linux/jiffies.h>
 #include "pcie.h"
 
+static DEFINE_IDA(card_num_ida);
+
 /*******************************************************
  * SysFS Attributes
  ******************************************************/
@@ -274,7 +277,6 @@ int kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	int err = 0;
 	struct kp2000_device *pcard;
-	static int card_count = 1;
 	int rv;
 	unsigned long reg_bar_phys_addr;
 	unsigned long reg_bar_phys_len;
@@ -300,9 +302,14 @@ int kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	/*
 	 * Step 2: Initialize trivial pcard elements
 	 */
-	pcard->card_num = card_count;
-	card_count++;
-	scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
+	err = ida_simple_get(&card_num_ida, 1, INT_MAX, GFP_KERNEL);
+	if (err < 0) {
+		dev_err(&pdev->dev, "probe: failed to get card number (%d)\n",
+			err);
+		goto out2;
+	}
+	pcard->card_num = err;
+	scnprintf(pcard->name, 16, "kpcard%u", pcard->card_num);
 
 	mutex_init(&pcard->sem);
 	lock_card(pcard);
@@ -517,6 +524,8 @@ int kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	pci_disable_device(pcard->pdev);
 out3:
 	unlock_card(pcard);
+	ida_simple_remove(&card_num_ida, pcard->card_num);
+out2:
 	kfree(pcard);
 	return err;
 }
@@ -550,5 +559,11 @@ void kp2000_pcie_remove(struct pci_dev *pdev)
 	pci_disable_device(pcard->pdev);
 	pci_set_drvdata(pdev, NULL);
 	unlock_card(pcard);
+	ida_simple_remove(&card_num_ida, pcard->card_num);
 	kfree(pcard);
 }
+
+void kp2000_pcie_destroy(void)
+{
+	ida_destroy(&card_num_ida);
+}
diff --git a/drivers/staging/kpc2000/kpc2000/kp2000_module.c b/drivers/staging/kpc2000/kpc2000/kp2000_module.c
index fa3bd266ba54..8da8d5f5f8cc 100644
--- a/drivers/staging/kpc2000/kpc2000/kp2000_module.c
+++ b/drivers/staging/kpc2000/kpc2000/kp2000_module.c
@@ -50,5 +50,6 @@ static void __exit  kp2000_pcie_exit(void)
 {
 	pci_unregister_driver(&kp2000_driver_inst);
 	class_destroy(kpc_uio_class);
+	kp2000_pcie_destroy();
 }
 module_exit(kp2000_pcie_exit);
diff --git a/drivers/staging/kpc2000/kpc2000/pcie.h b/drivers/staging/kpc2000/kpc2000/pcie.h
index 8a032a5a962e..b416b792250b 100644
--- a/drivers/staging/kpc2000/kpc2000/pcie.h
+++ b/drivers/staging/kpc2000/kpc2000/pcie.h
@@ -84,10 +84,11 @@ struct kp2000_device {
 extern struct class *kpc_uio_class;
 extern struct attribute *kpc_uio_class_attrs[];
 
-int   kp2000_pcie_probe(struct pci_dev *dev, const struct pci_device_id *id);
-void  kp2000_pcie_remove(struct pci_dev *pdev);
-int   kp2000_probe_cores(struct kp2000_device *pcard);
-void  kp2000_remove_cores(struct kp2000_device *pcard);
+int  kp2000_pcie_probe(struct pci_dev *dev, const struct pci_device_id *id);
+void kp2000_pcie_remove(struct pci_dev *pdev);
+void kp2000_pcie_destroy(void);
+int  kp2000_probe_cores(struct kp2000_device *pcard);
+void kp2000_remove_cores(struct kp2000_device *pcard);
 
 extern struct file_operations  kp2000_fops;
 
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 7/8] staging: kpc2000: simplified kp2000_device retrieval in device attribute call-backs.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                             ` (13 preceding siblings ...)
  2019-05-20 19:52           ` [PATCH v4 6/8] staging: kpc2000: use IDA to assign card numbers Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  2019-05-20 19:52           ` [PATCH v4 8/8] staging: kpc2000: removed superfluous NULL checks from " Jeremy Sowden
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

All the call-backs used the same formula to retrieve the pcard from dev:

  struct pci_dev *pdev = to_pci_dev(dev);
  struct kp2000_device *pcard;

  if (!pdev)
    return NULL;

  pcard = pci_get_drvdata(pdev);

Since to_pci_dev is a wrapper for container_of, it will not return NULL,
and since pci_get_drvdata just calls dev_get_drvdata on the dev member
of pdev, this is equivalent to:

  struct kp2000_device *pcard = dev_get_drvdata(&(container_of(dev, struct pci_dev, dev)->dev));

and we can simplify it to:

  struct kp2000_device *pcard = dev_get_drvdata(dev);

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 28 +++++++++-----------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index a8383e8159eb..f6043ef7b55b 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -25,20 +25,10 @@ static DEFINE_IDA(card_num_ida);
  * SysFS Attributes
  ******************************************************/
 
-static struct kp2000_device *get_pcard(struct device *dev)
-{
-	struct pci_dev *pdev = to_pci_dev(dev);
-
-	if (!pdev)
-		return NULL;
-
-	return pci_get_drvdata(pdev);
-}
-
 static ssize_t ssid_show(struct device *dev, struct device_attribute *attr,
 			 char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -50,7 +40,7 @@ static DEVICE_ATTR_RO(ssid);
 static ssize_t ddna_show(struct device *dev, struct device_attribute *attr,
 			 char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -62,7 +52,7 @@ static DEVICE_ATTR_RO(ddna);
 static ssize_t card_id_show(struct device *dev, struct device_attribute *attr,
 			    char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -74,7 +64,7 @@ static DEVICE_ATTR_RO(card_id);
 static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr,
 			   char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -86,7 +76,7 @@ static DEVICE_ATTR_RO(hw_rev);
 static ssize_t build_show(struct device *dev, struct device_attribute *attr,
 			  char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -98,7 +88,7 @@ static DEVICE_ATTR_RO(build);
 static ssize_t build_date_show(struct device *dev,
 			       struct device_attribute *attr, char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -110,7 +100,7 @@ static DEVICE_ATTR_RO(build_date);
 static ssize_t build_time_show(struct device *dev,
 			       struct device_attribute *attr, char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -122,7 +112,7 @@ static DEVICE_ATTR_RO(build_time);
 static ssize_t cpld_reg_show(struct device *dev, struct device_attribute *attr,
 			     char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	u64 val;
 
 	if (!pcard)
@@ -137,7 +127,7 @@ static ssize_t cpld_reconfigure(struct device *dev,
 				struct device_attribute *attr,
 				const char *buf, size_t count)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	long wr_val;
 	int rv;
 
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 8/8] staging: kpc2000: removed superfluous NULL checks from device attribute call-backs.
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
                             ` (14 preceding siblings ...)
  2019-05-20 19:52           ` [PATCH v4 7/8] staging: kpc2000: simplified kp2000_device retrieval in device attribute call-backs Jeremy Sowden
@ 2019-05-20 19:52           ` Jeremy Sowden
  15 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 19:52 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH

All the attribute show call-backs check whether pcard is NULL.  However,
pci_set_drvdata(pdev, pcard) is called before the sysfs files are
created during probe, and pci_set_drvdata(pdev, NULL) is not called
until after they are destroyed during remove; therefore, pcard will not
be NULL, and we can drop the checks.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 27 --------------------------
 1 file changed, 27 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index f6043ef7b55b..4a0af2645747 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -30,9 +30,6 @@ static ssize_t ssid_show(struct device *dev, struct device_attribute *attr,
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-	if (!pcard)
-		return -ENXIO;
-
 	return sprintf(buf, "%016llx\n", pcard->ssid);
 }
 static DEVICE_ATTR_RO(ssid);
@@ -42,9 +39,6 @@ static ssize_t ddna_show(struct device *dev, struct device_attribute *attr,
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-	if (!pcard)
-		return -ENXIO;
-
 	return sprintf(buf, "%016llx\n", pcard->ddna);
 }
 static DEVICE_ATTR_RO(ddna);
@@ -54,9 +48,6 @@ static ssize_t card_id_show(struct device *dev, struct device_attribute *attr,
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-	if (!pcard)
-		return -ENXIO;
-
 	return sprintf(buf, "%08x\n", pcard->card_id);
 }
 static DEVICE_ATTR_RO(card_id);
@@ -66,9 +57,6 @@ static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr,
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-	if (!pcard)
-		return -ENXIO;
-
 	return sprintf(buf, "%08x\n", pcard->hardware_revision);
 }
 static DEVICE_ATTR_RO(hw_rev);
@@ -78,9 +66,6 @@ static ssize_t build_show(struct device *dev, struct device_attribute *attr,
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-	if (!pcard)
-		return -ENXIO;
-
 	return sprintf(buf, "%08x\n", pcard->build_version);
 }
 static DEVICE_ATTR_RO(build);
@@ -90,9 +75,6 @@ static ssize_t build_date_show(struct device *dev,
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-	if (!pcard)
-		return -ENXIO;
-
 	return sprintf(buf, "%08x\n", pcard->build_datestamp);
 }
 static DEVICE_ATTR_RO(build_date);
@@ -102,9 +84,6 @@ static ssize_t build_time_show(struct device *dev,
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-	if (!pcard)
-		return -ENXIO;
-
 	return sprintf(buf, "%08x\n", pcard->build_timestamp);
 }
 static DEVICE_ATTR_RO(build_time);
@@ -115,9 +94,6 @@ static ssize_t cpld_reg_show(struct device *dev, struct device_attribute *attr,
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	u64 val;
 
-	if (!pcard)
-		return -ENXIO;
-
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	return sprintf(buf, "%016llx\n", val);
 }
@@ -131,9 +107,6 @@ static ssize_t cpld_reconfigure(struct device *dev,
 	long wr_val;
 	int rv;
 
-	if (!pcard)
-		return -ENXIO;
-
 	rv = kstrtol(buf, 0, &wr_val);
 	if (rv < 0)
 		return rv;
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* git-send-email cock-up [Was: Re: [PATCH v3 0/6] staging: kpc2000: another batch of fixes]
  2019-05-17 11:03       ` [PATCH v3 0/6] staging: kpc2000: another batch of fixes Jeremy Sowden
                           ` (6 preceding siblings ...)
  2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
@ 2019-05-20 20:03         ` Jeremy Sowden
  7 siblings, 0 replies; 63+ messages in thread
From: Jeremy Sowden @ 2019-05-20 20:03 UTC (permalink / raw)
  To: Linux Driver Project Developer List; +Cc: Greg KH


[-- Attachment #1.1: Type: text/plain, Size: 158 bytes --]

I've mucked up sending out v4 of this series.  Please ignore the
messages I just sent.  I'll send the right ones out as v5 shortly.

Sorry for the noise.

J.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 169 bytes --]

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/6] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs.
  2019-05-17 11:54           ` Greg KH
  2019-05-17 12:18             ` Jeremy Sowden
@ 2019-05-21 11:23             ` Dan Carpenter
  2019-05-22 12:30               ` Greg KH
  1 sibling, 1 reply; 63+ messages in thread
From: Dan Carpenter @ 2019-05-21 11:23 UTC (permalink / raw)
  To: Greg KH; +Cc: Linux Driver Project Developer List

On Fri, May 17, 2019 at 01:54:51PM +0200, Greg KH wrote:
> On Fri, May 17, 2019 at 12:03:12PM +0100, Jeremy Sowden wrote:
> >  static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
> >  {
> > -    struct pci_dev *pdev = to_pci_dev(dev);
> > -    struct kp2000_device *pcard;
> > -
> > -    if (!pdev)  return -ENXIO;
> > -    pcard = pci_get_drvdata(pdev);
> > -    if (!pcard)  return -ENXIO;
> > +    struct kp2000_device *pcard = dev_get_drvdata(dev);
> 
> Wait, dev_get_drvdata() is not returning you the same pointer that
> pci_get_drvdata() does.  So I think this is now broken :(
> 

It looks sort of weird but it's fine.

> What this should look like is this:
> 	struct pci_dev *pdev = to_pci_dev(dev);
> 	struct kp200_device *pcard = pci_get_drvdata(pdev);
> 
> 	if (!pcard)
> 		return -ENODEV;
> 
> that is IF the driver really is setting the pci dev data to NULL when
> the device is removed from the driver.  Is it?

Yes.  The pci_get_drvdata() is only set to NULL after we remove the
sysfs files so pci_get_drvdata() always returns a valid pointer.

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v3 3/6] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs.
  2019-05-21 11:23             ` Dan Carpenter
@ 2019-05-22 12:30               ` Greg KH
  0 siblings, 0 replies; 63+ messages in thread
From: Greg KH @ 2019-05-22 12:30 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Linux Driver Project Developer List

On Tue, May 21, 2019 at 02:23:13PM +0300, Dan Carpenter wrote:
> On Fri, May 17, 2019 at 01:54:51PM +0200, Greg KH wrote:
> > On Fri, May 17, 2019 at 12:03:12PM +0100, Jeremy Sowden wrote:
> > >  static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
> > >  {
> > > -    struct pci_dev *pdev = to_pci_dev(dev);
> > > -    struct kp2000_device *pcard;
> > > -
> > > -    if (!pdev)  return -ENXIO;
> > > -    pcard = pci_get_drvdata(pdev);
> > > -    if (!pcard)  return -ENXIO;
> > > +    struct kp2000_device *pcard = dev_get_drvdata(dev);
> > 
> > Wait, dev_get_drvdata() is not returning you the same pointer that
> > pci_get_drvdata() does.  So I think this is now broken :(
> > 
> 
> It looks sort of weird but it's fine.
> 
> > What this should look like is this:
> > 	struct pci_dev *pdev = to_pci_dev(dev);
> > 	struct kp200_device *pcard = pci_get_drvdata(pdev);
> > 
> > 	if (!pcard)
> > 		return -ENODEV;
> > 
> > that is IF the driver really is setting the pci dev data to NULL when
> > the device is removed from the driver.  Is it?
> 
> Yes.  The pci_get_drvdata() is only set to NULL after we remove the
> sysfs files so pci_get_drvdata() always returns a valid pointer.

Ugh, I am wrong, it's not as if I didn't actually write the
dev_get_drvdata() and pci_get_drvdata() code 15+ years ago, you would
think I would have remembered something like this :(

Anyway, patches look good, sorry for the noise...

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 63+ messages in thread

end of thread, other threads:[~2019-05-22 12:30 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-16 20:04 [PATCH 00/11] staging: kpc2000: another batch of fixes Jeremy Sowden
2019-05-16 20:04 ` [PATCH 01/11] staging: kpc2000: removed trailing white-space Jeremy Sowden
2019-05-16 20:04 ` [PATCH 02/11] staging: kpc2000: add separate show functions for kpc_uio_class device attributes Jeremy Sowden
2019-05-16 20:17   ` Matt Sickler
2019-05-16 20:46     ` Jeremy Sowden
2019-05-16 20:45   ` Greg KH
2019-05-16 21:06     ` Jeremy Sowden
2019-05-16 20:04 ` [PATCH 03/11] staging: kpc2000: define all kpc_uio_class device attributes as read-only Jeremy Sowden
2019-05-16 20:04 ` [PATCH 04/11] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
2019-05-16 20:04 ` [PATCH 05/11] staging: kpc2000: declare all kpc_uio_class device attributes as static Jeremy Sowden
2019-05-16 20:04 ` [PATCH 06/11] staging: kpc2000: use atomic_t to assign card numbers Jeremy Sowden
2019-05-16 20:04 ` [PATCH 07/11] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs Jeremy Sowden
2019-05-16 20:04 ` [PATCH 08/11] staging: kpc2000: add separate show functions for readable kp device attributes Jeremy Sowden
2019-05-16 20:04 ` [PATCH 09/11] staging: kpc2000: formatting fixes for " Jeremy Sowden
2019-05-16 20:04 ` [PATCH 10/11] staging: kpc2000: define read-only kp device attributes as read-only Jeremy Sowden
2019-05-16 20:04 ` [PATCH 11/11] staging: kpc2000: declare all kp device attributes as static Jeremy Sowden
2019-05-16 21:38 ` [PATCH v2 0/9] staging: kpc2000: another batch of fixes Jeremy Sowden
2019-05-16 21:38   ` [PATCH v2 1/9] staging: kpc2000: removed trailing white-space Jeremy Sowden
2019-05-17  7:30     ` Greg KH
2019-05-17 11:03       ` [PATCH v3 0/6] staging: kpc2000: another batch of fixes Jeremy Sowden
2019-05-17 11:03         ` [PATCH v3 1/6] staging: kpc2000: add separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
2019-05-17 11:03         ` [PATCH v3 2/6] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
2019-05-17 11:03         ` [PATCH v3 3/6] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs Jeremy Sowden
2019-05-17 11:54           ` Greg KH
2019-05-17 12:18             ` Jeremy Sowden
2019-05-21 11:23             ` Dan Carpenter
2019-05-22 12:30               ` Greg KH
2019-05-17 11:03         ` [PATCH v3 4/6] staging: kpc2000: formatting fixes for kp device attributes Jeremy Sowden
2019-05-17 11:03         ` [PATCH v3 5/6] staging: kpc2000: add separate show functions for readable kp device attributes, defined them as read-only, and declared them static Jeremy Sowden
2019-05-17 11:03         ` [PATCH v3 6/6] staging: kpc2000: use IDA to assign card numbers Jeremy Sowden
2019-05-17 11:50           ` Greg KH
2019-05-17 12:19             ` Jeremy Sowden
2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
2019-05-20 19:52           ` [PATCH 2/8] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
2019-05-20 19:52           ` [PATCH 3/8] staging: kpc2000: improved formatting of core.c Jeremy Sowden
2019-05-20 19:52           ` [PATCH 4/8] staging: kpc2000: added a helper to get struct kp2000_device from struct device Jeremy Sowden
2019-05-20 19:52           ` [PATCH 5/8] staging: kpc2000: added separate show functions for readable kp device attributes, defined them as read-only, and declared them static Jeremy Sowden
2019-05-20 19:52           ` [PATCH 6/8] staging: kpc2000: use IDA to assign card numbers Jeremy Sowden
2019-05-20 19:52           ` [PATCH 7/8] staging: kpc2000: simplified kp2000_device retrieval in device attribute call-backs Jeremy Sowden
2019-05-20 19:52           ` [PATCH 8/8] staging: kpc2000: removed superfluous NULL checks from " Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 0/8] staging: kpc2000: another batch of fixes Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 2/8] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 3/8] staging: kpc2000: improved formatting of core.c Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 4/8] staging: kpc2000: added a helper to get struct kp2000_device from struct device Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 5/8] staging: kpc2000: added separate show functions for readable kp device attributes, defined them as read-only, and declared them static Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 6/8] staging: kpc2000: use IDA to assign card numbers Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 7/8] staging: kpc2000: simplified kp2000_device retrieval in device attribute call-backs Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 8/8] staging: kpc2000: removed superfluous NULL checks from " Jeremy Sowden
2019-05-20 20:03         ` git-send-email cock-up [Was: Re: [PATCH v3 0/6] staging: kpc2000: another batch of fixes] Jeremy Sowden
2019-05-16 21:38   ` [PATCH v2 2/9] staging: kpc2000: add separate show functions for kpc_uio_class device attributes and defined them as read-only Jeremy Sowden
2019-05-17  7:15     ` Greg KH
2019-05-16 21:38   ` [PATCH v2 3/9] staging: kpc2000: declare all kpc_uio_class device attributes as static Jeremy Sowden
2019-05-17  7:15     ` Greg KH
2019-05-16 21:38   ` [PATCH v2 4/9] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
2019-05-17  7:14     ` Greg KH
2019-05-16 21:38   ` [PATCH v2 5/9] staging: kpc2000: use atomic_t to assign card numbers Jeremy Sowden
2019-05-16 22:14     ` Matt Sickler
2019-05-17  7:13       ` Greg KH
2019-05-16 21:38   ` [PATCH v2 6/9] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs Jeremy Sowden
2019-05-16 21:38   ` [PATCH v2 7/9] staging: kpc2000: formatting fixes for kp device attributes Jeremy Sowden
2019-05-16 21:38   ` [PATCH v2 8/9] staging: kpc2000: add separate show functions for readable kp device attributes, and defined them as read-only Jeremy Sowden
2019-05-16 21:38   ` [PATCH v2 9/9] staging: kpc2000: declare all kp device attributes as static Jeremy Sowden

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.