linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] MCB patches for v4.7
@ 2016-05-03  7:46 Johannes Thumshirn
  2016-05-03  7:46 ` [PATCH 1/6] mcb: Correctly initialize the bus's device Johannes Thumshirn
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Johannes Thumshirn @ 2016-05-03  7:46 UTC (permalink / raw)
  To: Greg KH; +Cc: Andreas Werner, Linux Kernel Mailinglist, Johannes Thumshirn

Hi Greg,

The following patches are the MCB updates for v4.7. These are mainly cleanups
and some bug fixes from Andreas and me. The only non cleanup/bugfix patch is
'mcb: export bus information via sysfs' which exports information about the
carrier FPGA to sysfs, like the revision number and model name of the FPGA,
so that a field technician can easily obtain these.

All patches have been tested by Andreas and have been on lkml for people to
comment as well as in my git tree located at:

git://git.kernel.org/pub/scm/linux/kernel/git/jth/linux.git tags/for-v4.7

Thanks,
	Johannes

Andreas Werner (3):
  mcb: Fixed bar number assignment for the gdd
  mcb: Replace ioremap and request_region with the devm version
  mcb: Delete num_cells variable which is not required

Johannes Thumshirn (3):
  mcb: Correctly initialize the bus's device
  mcb: export bus information via sysfs
  mcb: Implement bus->dev.release callback

 Documentation/ABI/testing/sysfs-bus-mcb | 29 ++++++++++
 drivers/mcb/mcb-core.c                  | 99 ++++++++++++++++++++++++++++++---
 drivers/mcb/mcb-internal.h              |  1 -
 drivers/mcb/mcb-parse.c                 | 17 ++----
 drivers/mcb/mcb-pci.c                   | 23 +++-----
 include/linux/mcb.h                     | 14 ++++-
 6 files changed, 144 insertions(+), 39 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-mcb

-- 
2.8.1

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

* [PATCH 1/6] mcb: Correctly initialize the bus's device
  2016-05-03  7:46 [PATCH 0/6] MCB patches for v4.7 Johannes Thumshirn
@ 2016-05-03  7:46 ` Johannes Thumshirn
  2016-05-03  7:46 ` [PATCH 2/6] mcb: export bus information via sysfs Johannes Thumshirn
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Johannes Thumshirn @ 2016-05-03  7:46 UTC (permalink / raw)
  To: Greg KH; +Cc: Andreas Werner, Linux Kernel Mailinglist, Johannes Thumshirn

The mcb bus' device member wasn't correctly initialized and thus wasn't placed
correctly into the driver model.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Andreas Werner <andreas.werner@men.de>
Tested-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/mcb/mcb-core.c | 19 ++++++++++++++++---
 include/linux/mcb.h    |  5 ++---
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/mcb/mcb-core.c b/drivers/mcb/mcb-core.c
index a4be451..1e336cc 100644
--- a/drivers/mcb/mcb-core.c
+++ b/drivers/mcb/mcb-core.c
@@ -187,6 +187,7 @@ struct mcb_bus *mcb_alloc_bus(struct device *carrier)
 {
 	struct mcb_bus *bus;
 	int bus_nr;
+	int rc;
 
 	bus = kzalloc(sizeof(struct mcb_bus), GFP_KERNEL);
 	if (!bus)
@@ -194,14 +195,26 @@ struct mcb_bus *mcb_alloc_bus(struct device *carrier)
 
 	bus_nr = ida_simple_get(&mcb_ida, 0, 0, GFP_KERNEL);
 	if (bus_nr < 0) {
-		kfree(bus);
-		return ERR_PTR(bus_nr);
+		rc = bus_nr;
+		goto err_free;
 	}
 
-	INIT_LIST_HEAD(&bus->children);
 	bus->bus_nr = bus_nr;
 	bus->carrier = carrier;
+
+	device_initialize(&bus->dev);
+	bus->dev.parent = carrier;
+	bus->dev.bus = &mcb_bus_type;
+
+	dev_set_name(&bus->dev, "mcb:%d", bus_nr);
+	rc = device_add(&bus->dev);
+	if (rc)
+		goto err_free;
+
 	return bus;
+err_free:
+	kfree(bus);
+	return ERR_PTR(rc);
 }
 EXPORT_SYMBOL_GPL(mcb_alloc_bus);
 
diff --git a/include/linux/mcb.h b/include/linux/mcb.h
index ed06e15..3efafbc 100644
--- a/include/linux/mcb.h
+++ b/include/linux/mcb.h
@@ -21,13 +21,12 @@ struct mcb_device;
 /**
  * struct mcb_bus - MEN Chameleon Bus
  *
- * @dev: pointer to carrier device
- * @children: the child busses
+ * @dev: bus device
+ * @carrier: pointer to carrier device
  * @bus_nr: mcb bus number
  * @get_irq: callback to get IRQ number
  */
 struct mcb_bus {
-	struct list_head children;
 	struct device dev;
 	struct device *carrier;
 	int bus_nr;
-- 
2.8.1

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

* [PATCH 2/6] mcb: export bus information via sysfs
  2016-05-03  7:46 [PATCH 0/6] MCB patches for v4.7 Johannes Thumshirn
  2016-05-03  7:46 ` [PATCH 1/6] mcb: Correctly initialize the bus's device Johannes Thumshirn
@ 2016-05-03  7:46 ` Johannes Thumshirn
  2016-05-03  8:02 ` [PATCH 0/6] MCB patches for v4.7 Johannes Thumshirn
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Johannes Thumshirn @ 2016-05-03  7:46 UTC (permalink / raw)
  To: Greg KH; +Cc: Andreas Werner, Linux Kernel Mailinglist, Johannes Thumshirn

Export information about the bus stored in the FPGA's header to userspace via
sysfs, instead of hiding it in pr_debug()s from everyone.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Andreas Werner <andreas.werner@men.de>
Tested-by: Andreas Werner <andreas.werner@men.de>
---
 Documentation/ABI/testing/sysfs-bus-mcb | 29 ++++++++++++++++
 drivers/mcb/mcb-core.c                  | 60 +++++++++++++++++++++++++++++++++
 drivers/mcb/mcb-internal.h              |  1 -
 drivers/mcb/mcb-parse.c                 | 15 +++------
 include/linux/mcb.h                     |  9 +++++
 5 files changed, 103 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-mcb

diff --git a/Documentation/ABI/testing/sysfs-bus-mcb b/Documentation/ABI/testing/sysfs-bus-mcb
new file mode 100644
index 0000000..77947c5
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-mcb
@@ -0,0 +1,29 @@
+What:		/sys/bus/mcb/devices/mcb:X
+Date:		March 2016
+KernelVersion:	4.7
+Contact:	Johannes Thumshirn <jth@kernel.org>
+Description:	Hardware chip or device hosting the MEN chameleon bus
+
+What:		/sys/bus/mcb/devices/mcb:X/revision
+Date:		March 2016
+KernelVersion:	4.7
+Contact:	Johannes Thumshirn <jth@kernel.org>
+Description:	The FPGA's revision number
+
+What:		/sys/bus/mcb/devices/mcb:X/minor
+Date:		March 2016
+KernelVersion:	4.7
+Contact:	Johannes Thumshirn <jth@kernel.org>
+Description:	The FPGA's minor number
+
+What:		/sys/bus/mcb/devices/mcb:X/model
+Date:		March 2016
+KernelVersion:	4.7
+Contact:	Johannes Thumshirn <jth@kernel.org>
+Description:	The FPGA's model number
+
+What:		/sys/bus/mcb/devices/mcb:X/name
+Date:		March 2016
+KernelVersion:	4.7
+Contact:	Johannes Thumshirn <jth@kernel.org>
+Description:	The FPGA's name
diff --git a/drivers/mcb/mcb-core.c b/drivers/mcb/mcb-core.c
index 1e336cc..9ae4d15 100644
--- a/drivers/mcb/mcb-core.c
+++ b/drivers/mcb/mcb-core.c
@@ -90,6 +90,60 @@ static void mcb_shutdown(struct device *dev)
 		mdrv->shutdown(mdev);
 }
 
+static ssize_t revision_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct mcb_bus *bus = to_mcb_bus(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%d\n", bus->revision);
+}
+static DEVICE_ATTR_RO(revision);
+
+static ssize_t model_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct mcb_bus *bus = to_mcb_bus(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%c\n", bus->model);
+}
+static DEVICE_ATTR_RO(model);
+
+static ssize_t minor_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct mcb_bus *bus = to_mcb_bus(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%d\n", bus->minor);
+}
+static DEVICE_ATTR_RO(minor);
+
+static ssize_t name_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct mcb_bus *bus = to_mcb_bus(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%s\n", bus->name);
+}
+static DEVICE_ATTR_RO(name);
+
+static struct attribute *mcb_bus_attrs[] = {
+	&dev_attr_revision.attr,
+	&dev_attr_model.attr,
+	&dev_attr_minor.attr,
+	&dev_attr_name.attr,
+	NULL,
+};
+
+static const struct attribute_group mcb_carrier_group = {
+	.attrs = mcb_bus_attrs,
+};
+
+static const struct attribute_group *mcb_carrier_groups[] = {
+	&mcb_carrier_group,
+	NULL,
+};
+
+
 static struct bus_type mcb_bus_type = {
 	.name = "mcb",
 	.match = mcb_match,
@@ -99,6 +153,11 @@ static struct bus_type mcb_bus_type = {
 	.shutdown = mcb_shutdown,
 };
 
+static struct device_type mcb_carrier_device_type = {
+	.name = "mcb-carrier",
+	.groups = mcb_carrier_groups,
+};
+
 /**
  * __mcb_register_driver() - Register a @mcb_driver at the system
  * @drv: The @mcb_driver
@@ -205,6 +264,7 @@ struct mcb_bus *mcb_alloc_bus(struct device *carrier)
 	device_initialize(&bus->dev);
 	bus->dev.parent = carrier;
 	bus->dev.bus = &mcb_bus_type;
+	bus->dev.type = &mcb_carrier_device_type;
 
 	dev_set_name(&bus->dev, "mcb:%d", bus_nr);
 	rc = device_add(&bus->dev);
diff --git a/drivers/mcb/mcb-internal.h b/drivers/mcb/mcb-internal.h
index fb7493d..5254e02 100644
--- a/drivers/mcb/mcb-internal.h
+++ b/drivers/mcb/mcb-internal.h
@@ -5,7 +5,6 @@
 
 #define PCI_VENDOR_ID_MEN		0x1a88
 #define PCI_DEVICE_ID_MEN_CHAMELEON	0x4d45
-#define CHAMELEON_FILENAME_LEN		12
 #define CHAMELEONV2_MAGIC		0xabce
 #define CHAM_HEADER_SIZE		0x200
 
diff --git a/drivers/mcb/mcb-parse.c b/drivers/mcb/mcb-parse.c
index 0049269..35f385b 100644
--- a/drivers/mcb/mcb-parse.c
+++ b/drivers/mcb/mcb-parse.c
@@ -113,16 +113,11 @@ int chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase,
 	}
 	p += hsize;
 
-	pr_debug("header->revision = %d\n", header->revision);
-	pr_debug("header->model = 0x%x ('%c')\n", header->model,
-		header->model);
-	pr_debug("header->minor = %d\n", header->minor);
-	pr_debug("header->bus_type = 0x%x\n", header->bus_type);
-
-
-	pr_debug("header->magic = 0x%x\n", header->magic);
-	pr_debug("header->filename = \"%.*s\"\n", CHAMELEON_FILENAME_LEN,
-		header->filename);
+	bus->revision = header->revision;
+	bus->model = header->model;
+	bus->minor = header->minor;
+	snprintf(bus->name, CHAMELEON_FILENAME_LEN + 1, "%s",
+		 header->filename);
 
 	for_each_chameleon_cell(dtype, p) {
 		switch (dtype) {
diff --git a/include/linux/mcb.h b/include/linux/mcb.h
index 3efafbc..ead13d2 100644
--- a/include/linux/mcb.h
+++ b/include/linux/mcb.h
@@ -15,6 +15,8 @@
 #include <linux/device.h>
 #include <linux/irqreturn.h>
 
+#define CHAMELEON_FILENAME_LEN 12
+
 struct mcb_driver;
 struct mcb_device;
 
@@ -25,11 +27,18 @@ struct mcb_device;
  * @carrier: pointer to carrier device
  * @bus_nr: mcb bus number
  * @get_irq: callback to get IRQ number
+ * @revision: the FPGA's revision number
+ * @model: the FPGA's model number
+ * @filename: the FPGA's name
  */
 struct mcb_bus {
 	struct device dev;
 	struct device *carrier;
 	int bus_nr;
+	u8 revision;
+	char model;
+	u8 minor;
+	char name[CHAMELEON_FILENAME_LEN + 1];
 	int (*get_irq)(struct mcb_device *dev);
 };
 #define to_mcb_bus(b) container_of((b), struct mcb_bus, dev)
-- 
2.8.1

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

* Re: [PATCH 0/6] MCB patches for v4.7
  2016-05-03  7:46 [PATCH 0/6] MCB patches for v4.7 Johannes Thumshirn
  2016-05-03  7:46 ` [PATCH 1/6] mcb: Correctly initialize the bus's device Johannes Thumshirn
  2016-05-03  7:46 ` [PATCH 2/6] mcb: export bus information via sysfs Johannes Thumshirn
@ 2016-05-03  8:02 ` Johannes Thumshirn
  2016-05-03 22:53   ` Greg KH
  2016-05-03 10:42 ` [PATCH 3/6] mcb: Fixed bar number assignment for the gdd Johannes Thumshirn
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 9+ messages in thread
From: Johannes Thumshirn @ 2016-05-03  8:02 UTC (permalink / raw)
  To: Greg KH; +Cc: Andreas Werner, Linux Kernel Mailinglist, Johannes Thumshirn

On Tue, May 03, 2016 at 09:46:21AM +0200, Johannes Thumshirn wrote:
> Hi Greg,
> 
> The following patches are the MCB updates for v4.7. These are mainly cleanups
> and some bug fixes from Andreas and me. The only non cleanup/bugfix patch is
> 'mcb: export bus information via sysfs' which exports information about the
> carrier FPGA to sysfs, like the revision number and model name of the FPGA,
> so that a field technician can easily obtain these.
> 
> All patches have been tested by Andreas and have been on lkml for people to
> comment as well as in my git tree located at:
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/jth/linux.git tags/for-v4.7
> 
> Thanks,
> 	Johannes
> 
> Andreas Werner (3):
>   mcb: Fixed bar number assignment for the gdd
>   mcb: Replace ioremap and request_region with the devm version
>   mcb: Delete num_cells variable which is not required
> 
> Johannes Thumshirn (3):
>   mcb: Correctly initialize the bus's device
>   mcb: export bus information via sysfs
>   mcb: Implement bus->dev.release callback
> 
>  Documentation/ABI/testing/sysfs-bus-mcb | 29 ++++++++++
>  drivers/mcb/mcb-core.c                  | 99 ++++++++++++++++++++++++++++++---
>  drivers/mcb/mcb-internal.h              |  1 -
>  drivers/mcb/mcb-parse.c                 | 17 ++----
>  drivers/mcb/mcb-pci.c                   | 23 +++-----
>  include/linux/mcb.h                     | 14 ++++-
>  6 files changed, 144 insertions(+), 39 deletions(-)
>  create mode 100644 Documentation/ABI/testing/sysfs-bus-mcb
> 
> -- 
> 2.8.1
> 

Somehow only two patches did make it through the mailserver, my apologies.

I'll re-send once I figured out what went wrong.

-- 
Johannes Thumshirn                                          Storage
jthumshirn@suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850

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

* [PATCH 3/6] mcb: Fixed bar number assignment for the gdd
  2016-05-03  7:46 [PATCH 0/6] MCB patches for v4.7 Johannes Thumshirn
                   ` (2 preceding siblings ...)
  2016-05-03  8:02 ` [PATCH 0/6] MCB patches for v4.7 Johannes Thumshirn
@ 2016-05-03 10:42 ` Johannes Thumshirn
  2016-05-03 10:42 ` [PATCH 4/6] mcb: Replace ioremap and request_region with the devm version Johannes Thumshirn
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Johannes Thumshirn @ 2016-05-03 10:42 UTC (permalink / raw)
  To: Greg KH
  Cc: Andreas Werner, Linux Kernel Mailinglist, stable, #, v3.15+,
	Johannes Thumshirn

From: Andreas Werner <andreas.werner@men.de>

The bar number is found in reg2 within the gdd. Therefore
we need to change the assigment from reg1 to reg2 which
is the correct location.

Signed-off-by: Andreas Werner <andreas.werner@men.de>
Fixes: '3764e82e5' drivers: Introduce MEN Chameleon Bus
Cc: stable@vger.kernel.org # v3.15+
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 drivers/mcb/mcb-parse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mcb/mcb-parse.c b/drivers/mcb/mcb-parse.c
index 35f385b..dbecbed 100644
--- a/drivers/mcb/mcb-parse.c
+++ b/drivers/mcb/mcb-parse.c
@@ -57,7 +57,7 @@ static int chameleon_parse_gdd(struct mcb_bus *bus,
 	mdev->id = GDD_DEV(reg1);
 	mdev->rev = GDD_REV(reg1);
 	mdev->var = GDD_VAR(reg1);
-	mdev->bar = GDD_BAR(reg1);
+	mdev->bar = GDD_BAR(reg2);
 	mdev->group = GDD_GRP(reg2);
 	mdev->inst = GDD_INS(reg2);
 
-- 
2.8.1

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

* [PATCH 4/6] mcb: Replace ioremap and request_region with the devm version
  2016-05-03  7:46 [PATCH 0/6] MCB patches for v4.7 Johannes Thumshirn
                   ` (3 preceding siblings ...)
  2016-05-03 10:42 ` [PATCH 3/6] mcb: Fixed bar number assignment for the gdd Johannes Thumshirn
@ 2016-05-03 10:42 ` Johannes Thumshirn
  2016-05-03 10:42 ` [PATCH 5/6] mcb: Delete num_cells variable which is not required Johannes Thumshirn
  2016-05-03 10:42 ` [PATCH 6/6] mcb: Implement bus->dev.release callback Johannes Thumshirn
  6 siblings, 0 replies; 9+ messages in thread
From: Johannes Thumshirn @ 2016-05-03 10:42 UTC (permalink / raw)
  To: Greg KH; +Cc: Andreas Werner, Linux Kernel Mailinglist, Johannes Thumshirn

From: Andreas Werner <andreas.werner@men.de>

Replaced ioremap with devm_ioremap and request_mem_region with
devm_request_mem_region. This makes the code much more cleaner.

Signed-off-by: Andreas Werner <andreas.werner@men.de>
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 drivers/mcb/mcb-pci.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/mcb/mcb-pci.c b/drivers/mcb/mcb-pci.c
index 67d5e7d..99dd9db 100644
--- a/drivers/mcb/mcb-pci.c
+++ b/drivers/mcb/mcb-pci.c
@@ -55,19 +55,20 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		goto out_disable;
 	}
 
-	res = request_mem_region(priv->mapbase, CHAM_HEADER_SIZE,
-				 KBUILD_MODNAME);
+	res = devm_request_mem_region(&pdev->dev, priv->mapbase,
+				      CHAM_HEADER_SIZE,
+				      KBUILD_MODNAME);
 	if (!res) {
 		dev_err(&pdev->dev, "Failed to request PCI memory\n");
 		ret = -EBUSY;
 		goto out_disable;
 	}
 
-	priv->base = ioremap(priv->mapbase, CHAM_HEADER_SIZE);
+	priv->base = devm_ioremap(&pdev->dev, priv->mapbase, CHAM_HEADER_SIZE);
 	if (!priv->base) {
 		dev_err(&pdev->dev, "Cannot ioremap\n");
 		ret = -ENOMEM;
-		goto out_release;
+		goto out_disable;
 	}
 
 	flags = pci_resource_flags(pdev, 0);
@@ -75,7 +76,7 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		ret = -ENOTSUPP;
 		dev_err(&pdev->dev,
 			"IO mapped PCI devices are not supported\n");
-		goto out_iounmap;
+		goto out_disable;
 	}
 
 	pci_set_drvdata(pdev, priv);
@@ -83,7 +84,7 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	priv->bus = mcb_alloc_bus(&pdev->dev);
 	if (IS_ERR(priv->bus)) {
 		ret = PTR_ERR(priv->bus);
-		goto out_iounmap;
+		goto out_disable;
 	}
 
 	priv->bus->get_irq = mcb_pci_get_irq;
@@ -101,10 +102,6 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 out_mcb_bus:
 	mcb_release_bus(priv->bus);
-out_iounmap:
-	iounmap(priv->base);
-out_release:
-	pci_release_region(pdev, 0);
 out_disable:
 	pci_disable_device(pdev);
 	return ret;
@@ -116,8 +113,6 @@ static void mcb_pci_remove(struct pci_dev *pdev)
 
 	mcb_release_bus(priv->bus);
 
-	iounmap(priv->base);
-	release_region(priv->mapbase, CHAM_HEADER_SIZE);
 	pci_disable_device(pdev);
 }
 
-- 
2.8.1

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

* [PATCH 5/6] mcb: Delete num_cells variable which is not required
  2016-05-03  7:46 [PATCH 0/6] MCB patches for v4.7 Johannes Thumshirn
                   ` (4 preceding siblings ...)
  2016-05-03 10:42 ` [PATCH 4/6] mcb: Replace ioremap and request_region with the devm version Johannes Thumshirn
@ 2016-05-03 10:42 ` Johannes Thumshirn
  2016-05-03 10:42 ` [PATCH 6/6] mcb: Implement bus->dev.release callback Johannes Thumshirn
  6 siblings, 0 replies; 9+ messages in thread
From: Johannes Thumshirn @ 2016-05-03 10:42 UTC (permalink / raw)
  To: Greg KH; +Cc: Andreas Werner, Linux Kernel Mailinglist, Johannes Thumshirn

From: Andreas Werner <andreas.werner@men.de>

The num_cells variable is only used in the dev_dbg print,
but we can directly use the ret variable which also includes the same
value.

Signed-off-by: Andreas Werner <andreas.werner@men.de>
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 drivers/mcb/mcb-pci.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/mcb/mcb-pci.c b/drivers/mcb/mcb-pci.c
index 99dd9db..b15a034 100644
--- a/drivers/mcb/mcb-pci.c
+++ b/drivers/mcb/mcb-pci.c
@@ -35,7 +35,6 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	struct resource *res;
 	struct priv *priv;
 	int ret;
-	int num_cells;
 	unsigned long flags;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(struct priv), GFP_KERNEL);
@@ -92,9 +91,8 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	ret = chameleon_parse_cells(priv->bus, priv->mapbase, priv->base);
 	if (ret < 0)
 		goto out_mcb_bus;
-	num_cells = ret;
 
-	dev_dbg(&pdev->dev, "Found %d cells\n", num_cells);
+	dev_dbg(&pdev->dev, "Found %d cells\n", ret);
 
 	mcb_bus_add_devices(priv->bus);
 
-- 
2.8.1

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

* [PATCH 6/6] mcb: Implement bus->dev.release callback
  2016-05-03  7:46 [PATCH 0/6] MCB patches for v4.7 Johannes Thumshirn
                   ` (5 preceding siblings ...)
  2016-05-03 10:42 ` [PATCH 5/6] mcb: Delete num_cells variable which is not required Johannes Thumshirn
@ 2016-05-03 10:42 ` Johannes Thumshirn
  6 siblings, 0 replies; 9+ messages in thread
From: Johannes Thumshirn @ 2016-05-03 10:42 UTC (permalink / raw)
  To: Greg KH; +Cc: Andreas Werner, Linux Kernel Mailinglist, Johannes Thumshirn

The mcb_bus structure previously was released in mcb_release_bus. This lead to
the following warning on module unload:

------------[ cut here ]------------
WARNING: CPU: 1 PID: 2032 at drivers/base/core.c:251 device_release+0x73/0x90
Device 'mcb:0' does not have a release() function, it is broken and must be fixed.
Modules linked in: men_z135_uart mcb_pci(-) mcb
CPU: 1 PID: 2032 Comm: rmmod Not tainted 4.6.0-rc4+ #3
Hardware name: N/A N/A/COMe-mBTi10, BIOS MVV1R921 X64 10/14/2015
 00000286 00000286 c0117de4 c12d6f16 c0117e2c c18be0d3 c0117dfc c104f6e1
 000000fb f5ccbe08 f5ccbe00 f5c64600 c0117e18 c104f728 00000009 00000000
 c0117e10 c18db674 c0117e2c c0117e3c c13ce5c3 c18be0d3 000000fb c18db674
Call Trace:
 [<c12d6f16>] dump_stack+0x47/0x61
 [<c104f6e1>] __warn+0xc1/0xe0
 [<c104f728>] warn_slowpath_fmt+0x28/0x30
 [<c13ce5c3>] device_release+0x73/0x90
 [<c12d92e4>] kobject_release+0x34/0x80
 [<c12d929d>] ? kobject_del+0x2d/0x40
 [<c12d9205>] kobject_put+0x25/0x50
 [<c13ce77f>] put_device+0xf/0x20
 [<c13d114b>] klist_devices_put+0xb/0x10
 [<c1752673>] klist_next+0x73/0xf0
 [<c13d1140>] ? unbind_store+0x100/0x100
 [<f8a23370>] ? mcb_bus_add_devices+0x30/0x30 [mcb]
 [<c13d0a81>] bus_for_each_dev+0x51/0x80
 [<f8a23319>] mcb_release_bus+0x19/0x40 [mcb]
 [<f8a23370>] ? mcb_bus_add_devices+0x30/0x30 [mcb]
 [<f8a2b033>] mcb_pci_remove+0x13/0x20 [mcb_pci]
 [<c130d358>] pci_device_remove+0x28/0xb0
 [<c13d201b>] __device_release_driver+0x7b/0x110
 [<c13d2847>] driver_detach+0x87/0x90
 [<c13d1b9b>] bus_remove_driver+0x3b/0x80
 [<c13d2ed0>] driver_unregister+0x20/0x50
 [<c130be53>] pci_unregister_driver+0x13/0x60
 [<f8a2b1f4>] mcb_pci_driver_exit+0xd/0xf [mcb_pci]
 [<c10be588>] SyS_delete_module+0x138/0x200
 [<c1159208>] ? ____fput+0x8/0x10
 [<c1068054>] ? task_work_run+0x74/0x90
 [<c1001879>] do_fast_syscall_32+0x69/0x120
 [<c1757597>] sysenter_past_esp+0x40/0x6a
---[ end trace 1ed34c2aa3019875 ]---

Release a mcb_bus' memory on the device's release callback, to avoid above
warning.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Reported-by: Andreas Werner <andreas.werner@men.de>
Tested-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/mcb/mcb-core.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/mcb/mcb-core.c b/drivers/mcb/mcb-core.c
index 9ae4d15..b73c6e7 100644
--- a/drivers/mcb/mcb-core.c
+++ b/drivers/mcb/mcb-core.c
@@ -83,8 +83,8 @@ static int mcb_remove(struct device *dev)
 
 static void mcb_shutdown(struct device *dev)
 {
+	struct mcb_driver *mdrv = to_mcb_driver(dev->driver);
 	struct mcb_device *mdev = to_mcb_device(dev);
-	struct mcb_driver *mdrv = mdev->driver;
 
 	if (mdrv && mdrv->shutdown)
 		mdrv->shutdown(mdev);
@@ -214,6 +214,7 @@ int mcb_device_register(struct mcb_bus *bus, struct mcb_device *dev)
 	int device_id;
 
 	device_initialize(&dev->dev);
+	mcb_bus_get(bus);
 	dev->dev.bus = &mcb_bus_type;
 	dev->dev.parent = bus->dev.parent;
 	dev->dev.release = mcb_release_dev;
@@ -237,6 +238,15 @@ out:
 }
 EXPORT_SYMBOL_GPL(mcb_device_register);
 
+static void mcb_free_bus(struct device *dev)
+{
+	struct mcb_bus *bus = to_mcb_bus(dev);
+
+	put_device(bus->carrier);
+	ida_simple_remove(&mcb_ida, bus->bus_nr);
+	kfree(bus);
+}
+
 /**
  * mcb_alloc_bus() - Allocate a new @mcb_bus
  *
@@ -259,12 +269,13 @@ struct mcb_bus *mcb_alloc_bus(struct device *carrier)
 	}
 
 	bus->bus_nr = bus_nr;
-	bus->carrier = carrier;
+	bus->carrier = get_device(carrier);
 
 	device_initialize(&bus->dev);
 	bus->dev.parent = carrier;
 	bus->dev.bus = &mcb_bus_type;
 	bus->dev.type = &mcb_carrier_device_type;
+	bus->dev.release = &mcb_free_bus;
 
 	dev_set_name(&bus->dev, "mcb:%d", bus_nr);
 	rc = device_add(&bus->dev);
@@ -273,6 +284,7 @@ struct mcb_bus *mcb_alloc_bus(struct device *carrier)
 
 	return bus;
 err_free:
+	put_device(carrier);
 	kfree(bus);
 	return ERR_PTR(rc);
 }
@@ -297,10 +309,6 @@ static void mcb_devices_unregister(struct mcb_bus *bus)
 void mcb_release_bus(struct mcb_bus *bus)
 {
 	mcb_devices_unregister(bus);
-
-	ida_simple_remove(&mcb_ida, bus->bus_nr);
-
-	kfree(bus);
 }
 EXPORT_SYMBOL_GPL(mcb_release_bus);
 
-- 
2.8.1

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

* Re: [PATCH 0/6] MCB patches for v4.7
  2016-05-03  8:02 ` [PATCH 0/6] MCB patches for v4.7 Johannes Thumshirn
@ 2016-05-03 22:53   ` Greg KH
  0 siblings, 0 replies; 9+ messages in thread
From: Greg KH @ 2016-05-03 22:53 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: Andreas Werner, Linux Kernel Mailinglist

On Tue, May 03, 2016 at 10:02:57AM +0200, Johannes Thumshirn wrote:
> On Tue, May 03, 2016 at 09:46:21AM +0200, Johannes Thumshirn wrote:
> > Hi Greg,
> > 
> > The following patches are the MCB updates for v4.7. These are mainly cleanups
> > and some bug fixes from Andreas and me. The only non cleanup/bugfix patch is
> > 'mcb: export bus information via sysfs' which exports information about the
> > carrier FPGA to sysfs, like the revision number and model name of the FPGA,
> > so that a field technician can easily obtain these.
> > 
> > All patches have been tested by Andreas and have been on lkml for people to
> > comment as well as in my git tree located at:
> > 
> > git://git.kernel.org/pub/scm/linux/kernel/git/jth/linux.git tags/for-v4.7
> > 
> > Thanks,
> > 	Johannes
> > 
> > Andreas Werner (3):
> >   mcb: Fixed bar number assignment for the gdd
> >   mcb: Replace ioremap and request_region with the devm version
> >   mcb: Delete num_cells variable which is not required
> > 
> > Johannes Thumshirn (3):
> >   mcb: Correctly initialize the bus's device
> >   mcb: export bus information via sysfs
> >   mcb: Implement bus->dev.release callback
> > 
> >  Documentation/ABI/testing/sysfs-bus-mcb | 29 ++++++++++
> >  drivers/mcb/mcb-core.c                  | 99 ++++++++++++++++++++++++++++++---
> >  drivers/mcb/mcb-internal.h              |  1 -
> >  drivers/mcb/mcb-parse.c                 | 17 ++----
> >  drivers/mcb/mcb-pci.c                   | 23 +++-----
> >  include/linux/mcb.h                     | 14 ++++-
> >  6 files changed, 144 insertions(+), 39 deletions(-)
> >  create mode 100644 Documentation/ABI/testing/sysfs-bus-mcb
> > 
> > -- 
> > 2.8.1
> > 
> 
> Somehow only two patches did make it through the mailserver, my apologies.
> 
> I'll re-send once I figured out what went wrong.

Odd, I got them all here, unless you resent them...

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

end of thread, other threads:[~2016-05-03 22:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-03  7:46 [PATCH 0/6] MCB patches for v4.7 Johannes Thumshirn
2016-05-03  7:46 ` [PATCH 1/6] mcb: Correctly initialize the bus's device Johannes Thumshirn
2016-05-03  7:46 ` [PATCH 2/6] mcb: export bus information via sysfs Johannes Thumshirn
2016-05-03  8:02 ` [PATCH 0/6] MCB patches for v4.7 Johannes Thumshirn
2016-05-03 22:53   ` Greg KH
2016-05-03 10:42 ` [PATCH 3/6] mcb: Fixed bar number assignment for the gdd Johannes Thumshirn
2016-05-03 10:42 ` [PATCH 4/6] mcb: Replace ioremap and request_region with the devm version Johannes Thumshirn
2016-05-03 10:42 ` [PATCH 5/6] mcb: Delete num_cells variable which is not required Johannes Thumshirn
2016-05-03 10:42 ` [PATCH 6/6] mcb: Implement bus->dev.release callback Johannes Thumshirn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).