Skip to contentSkip to conversation

staging: gasket: fixes and cleanups

PATCH Superseded Todd Poynor 2 participants 7 messages Jul 28, 2018 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover staging: gasket: fixes and cleanups

From: Todd Poynor <[email protected]>

The fun continues with gasket+apex: remove dead code and unnecessary stuff, fixup apex PCI class for devices that advertise class 0 (undefined), and make sure the struct device doesn't go away on us. Most of these from review comments of previous patch series.

Todd Poynor (5):
staging: gasket: sysfs: remove check for refcount already zero
staging: gasket: apex: fixup undefined PCI class
staging: gasket: sysfs: remove unnecessary NULL check on device ptr
staging: gasket: page table: remove code for "no dma_ops"
staging: gasket: core: hold reference on device kobj while in use

 drivers/staging/gasket/apex_driver.c       |  7 +++
 drivers/staging/gasket/gasket_core.c       |  5 +-
 drivers/staging/gasket/gasket_page_table.c | 58 +++-------------------
 drivers/staging/gasket/gasket_page_table.h |  3 +-
 drivers/staging/gasket/gasket_sysfs.c      |  7 ---
 5 files changed, 17 insertions(+), 63 deletions(-)
Signature · 1 line
2.18.0.345.g5c9ce644c3-goog
#1 lore raw

PATCH 1/5 staging: gasket: sysfs: remove check for refcount already zero

From: Todd Poynor <[email protected]>

Remove the check for refcount already zero, which shouldn't be necessary.

---
 drivers/staging/gasket/gasket_sysfs.c | 2 --
 1 file changed, 2 deletions(-)
drivers/staging/gasket/gasket_sysfs.c +0 -2
index 418b81797e638..2d8647de697cd 100644
@@ -111,8 +111,6 @@ static void put_mapping(struct gasket_sysfs_mapping *mapping)
 	}
 
 	mutex_lock(&mapping->mutex);
-	if (refcount_read(&mapping->refcount.refcount) == 0)
-		dev_err(mapping->device, "Refcount is already 0\n");
 	if (kref_put(&mapping->refcount, release_entry)) {
 		dev_dbg(mapping->device, "Removing Gasket sysfs mapping\n");
 		/*
Signature · 1 line
2.18.0.345.g5c9ce644c3-goog
#2 lore raw

PATCH 2/5 staging: gasket: apex: fixup undefined PCI class

In reply to Todd Poynor

From: Todd Poynor <[email protected]>

Apex chips with class 0 (PCI_CLASS_NOT_DEFINED) fixed up to PCI_CLASS_SYSTEM_OTHER to enable PCI resource assignments.

---
 drivers/staging/gasket/apex_driver.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/staging/gasket/apex_driver.c +7 -0
index 73fc2683a834d..ab466d49608a7 100644
@@ -739,3 +739,10 @@ static ssize_t sysfs_show(
 	gasket_sysfs_put_device_data(device, gasket_dev);
 	return ret;
 }
+
+static void apex_pci_fixup_class(struct pci_dev *pdev)
+{
+	pdev->class = (PCI_CLASS_SYSTEM_OTHER << 8) | pdev->class;
+}
+DECLARE_PCI_FIXUP_CLASS_HEADER(APEX_PCI_VENDOR_ID, APEX_PCI_DEVICE_ID,
+			       PCI_CLASS_NOT_DEFINED, 8, apex_pci_fixup_class);
Signature · 1 line
2.18.0.345.g5c9ce644c3-goog
#3 lore raw

PATCH 3/5 staging: gasket: sysfs: remove unnecessary NULL check on device ptr

In reply to Todd Poynor

From: Todd Poynor <[email protected]>

The device pointer passed into get_mapping() will never be NULL; the check is unnecessary.

---
 drivers/staging/gasket/gasket_sysfs.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/staging/gasket/gasket_sysfs.c +0 -5
index 2d8647de697cd..da972ce0e0db0 100644
@@ -67,11 +67,6 @@ static struct gasket_sysfs_mapping *get_mapping(struct device *device)
 {
 	int i;
 
-	if (!device) {
-		pr_debug("%s: Received NULL device\n", __func__);
-		return NULL;
-	}
-
 	for (i = 0; i < GASKET_SYSFS_NUM_MAPPINGS; i++) {
 		mutex_lock(&dev_mappings[i].mutex);
 		if (dev_mappings[i].device == device) {
Signature · 1 line
2.18.0.345.g5c9ce644c3-goog
#4 lore raw

PATCH 4/5 staging: gasket: page table: remove code for "no dma_ops"

In reply to Todd Poynor

From: Todd Poynor <[email protected]>

Remove code with TODOs on it for working around apparent problems previously seen in a qemu environment where dma_ops was not set correctly. There is no user of this in the current code.

---
 drivers/staging/gasket/gasket_core.c       |  2 +-
 drivers/staging/gasket/gasket_page_table.c | 58 +++-------------------
 drivers/staging/gasket/gasket_page_table.h |  3 +-
 3 files changed, 8 insertions(+), 55 deletions(-)
drivers/staging/gasket/gasket_core.c +1 -1
index f44805c38159b..859a6df9e12df 100644
@@ -916,7 +916,7 @@ static int gasket_enable_dev(
 			&gasket_dev->bar_data[
 				driver_desc->page_table_bar_index],
 			&driver_desc->page_table_configs[tbl_idx],
-			gasket_dev->dev, gasket_dev->pci_dev, true);
+			gasket_dev->dev, gasket_dev->pci_dev);
 		if (ret) {
 			dev_err(gasket_dev->dev,
 				"Couldn't init page table %d: %d\n",
drivers/staging/gasket/gasket_page_table.c +6 -52

94 lines not on this page · raw message

drivers/staging/gasket/gasket_page_table.h +1 -2
index 0e8afdb8c1139..765588649365f 100644
@@ -37,7 +37,6 @@ struct gasket_page_table;
  *                 translation table.
  * @device: Device structure for the underlying device. Only used for logging.
  * @pci_dev: PCI system descriptor for the underlying device.
- * @bool has_dma_ops: Whether the page table uses arch specific dma_ops or
  * whether the driver will supply its own.
  *
  * Description: Allocates and initializes data to track address translation -
@@ -51,7 +50,7 @@ int gasket_page_table_init(
 	struct gasket_page_table **ppg_tbl,
 	const struct gasket_bar_data *bar_data,
 	const struct gasket_page_table_config *page_table_config,
-	struct device *device, struct pci_dev *pci_dev, bool dma_ops);
+	struct device *device, struct pci_dev *pci_dev);
 
 /*
  * Deallocate and cleanup page table data.
Signature · 1 line
2.18.0.345.g5c9ce644c3-goog
#5 lore raw

PATCH 5/5 staging: gasket: core: hold reference on device kobj while in use

In reply to Todd Poynor

From: Todd Poynor <[email protected]>

Hold a reference on the struct device kobject while a pointer to that device is in use by gasket.

---
 drivers/staging/gasket/gasket_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/gasket/gasket_core.c +2 -1
index 859a6df9e12df..1dc7273e38734 100644
@@ -449,6 +449,7 @@ static int gasket_alloc_dev(
 	gasket_dev->dev_idx = dev_idx;
 	snprintf(gasket_dev->kobj_name, GASKET_NAME_MAX, "%s", kobj_name);
 	gasket_dev->dev = parent;
+	kobject_get(&gasket_dev->dev->kobj);
 	/* gasket_bar_data is uninitialized. */
 	gasket_dev->num_page_tables = driver_desc->num_page_tables;
 	/* max_page_table_size and *page table are uninit'ed */
@@ -487,7 +488,7 @@ static void gasket_free_dev(struct gasket_dev *gasket_dev)
 	mutex_lock(&internal_desc->mutex);
 	internal_desc->devs[gasket_dev->dev_idx] = NULL;
 	mutex_unlock(&internal_desc->mutex);
-
+	kobject_put(&gasket_dev->dev->kobj);
 	kfree(gasket_dev);
 }
 
Signature · 1 line
2.18.0.345.g5c9ce644c3-goog
#6 lore raw

Re: [PATCH 5/5] staging: gasket: core: hold reference on device kobj while in use

Quoted 16 lines · Todd Poynor

From: Todd Poynor <[email protected]>

Hold a reference on the struct device kobject while a pointer to that device is in use by gasket.

---
 drivers/staging/gasket/gasket_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/gasket/gasket_core.c +0 -0
index 859a6df9e12df..1dc7273e38734 100644

drivers/staging/gasket/gasket_core.c static int gasket_alloc_dev( · line 452

Quoted 4 lines
drivers/staging/gasket/gasket_core.c +1 -0
@@ -449,6 +449,7 @@ static int gasket_alloc_dev(
 	gasket_dev->dev_idx = dev_idx;
 	snprintf(gasket_dev->kobj_name, GASKET_NAME_MAX, "%s", kobj_name);
 	gasket_dev->dev = parent;
+	kobject_get(&gasket_dev->dev->kobj);

Hint, if you are a driver, working with devices, you should never call a kobject_* or sysfs_* call. If you are, you are doing something really wrong and odd and should seriously reconsider it. No driver should ever be touching a "raw" kobject.

For this case, get_device()/put_device() is what you should be using.

thanks,

greg k-h