[dahdi-commits] tzafrir: linux/trunk r10449 - /linux/trunk/drivers/dahdi/
SVN commits to the DAHDI project
dahdi-commits at lists.digium.com
Wed Jan 25 15:18:04 CST 2012
Author: tzafrir
Date: Wed Jan 25 15:18:00 2012
New Revision: 10449
URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=10449
Log:
A parent-less device should not crash dahdi
* A parent-less device should not crash dahdi:
- Access span->parent->dev instead of span->parent-dev.parent
in soem cases.
- Access span->parent->dev via new inline span_device()
- Use span_device() in all dahdi_dev_{dbg,info}()
* Allow low-level drivers to set their device name.
- Drivers that don't use this feature get the default name
based on the parent device name
- Parent-less devices which don't set their name, fails
to register with -EINVAL
Signed-off-by: Oron Peled <oron.peled at xorcom.com>
Acked-by: Tzafrir Cohen <tzafrir.cohen at xorcom.com>
Modified:
linux/trunk/drivers/dahdi/dahdi-base.c
linux/trunk/drivers/dahdi/dahdi-sysfs.c
Modified: linux/trunk/drivers/dahdi/dahdi-base.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/dahdi-base.c?view=diff&rev=10449&r1=10448&r2=10449
==============================================================================
--- linux/trunk/drivers/dahdi/dahdi-base.c (original)
+++ linux/trunk/drivers/dahdi/dahdi-base.c Wed Jan 25 15:18:00 2012
@@ -357,6 +357,11 @@
/* The first zone on the list is the default zone. */
static LIST_HEAD(tone_zones);
+
+static inline struct device *span_device(struct dahdi_span *span)
+{
+ return &span->parent->dev;
+}
/* Protects the span_list and pseudo_chans lists from concurrent access in
* process context. The spin_lock is needed to synchronize with the interrupt
@@ -6649,7 +6654,7 @@
set_spanno_and_basechan(struct dahdi_span *span, u32 spanno, u32 basechan)
{
int i;
- dahdi_dev_dbg(ASSIGN, span->parent->dev.parent,
+ dahdi_dev_dbg(ASSIGN, span_device(span),
"set: spanno=%d, basechan=%d (span->channels=%d)\n",
spanno, basechan, span->channels);
span->spanno = spanno;
@@ -6673,7 +6678,7 @@
unsigned int spanno = 1;
unsigned int basechan = 1;
- dahdi_dev_dbg(ASSIGN, span->parent->dev.parent,
+ dahdi_dev_dbg(ASSIGN, span_device(span),
"assign: channels=%d\n", span->channels);
list_for_each_entry(pos, &span_list, spans_node) {
@@ -6693,7 +6698,7 @@
basechan = pos->chans[0]->channo + pos->channels;
}
- dahdi_dev_dbg(ASSIGN, span->parent->dev.parent,
+ dahdi_dev_dbg(ASSIGN, span_device(span),
"good: spanno=%d, basechan=%d (span->channels=%d)\n",
spanno, basechan, span->channels);
set_spanno_and_basechan(span, spanno, basechan);
@@ -6743,20 +6748,20 @@
struct dahdi_span *pos;
unsigned int next_channo;
- dahdi_dev_dbg(ASSIGN, span->parent->dev.parent,
+ dahdi_dev_dbg(ASSIGN, span_device(span),
"check: spanno=%d, basechan=%d (span->channels=%d)\n",
spanno, basechan, span->channels);
list_for_each_entry(pos, &span_list, spans_node) {
next_channo = _get_next_channo(pos);
- dahdi_dev_dbg(ASSIGN, span->parent->dev.parent,
+ dahdi_dev_dbg(ASSIGN, span_device(span),
"pos: spanno=%d channels=%d (next_channo=%d)\n",
pos->spanno, pos->channels, next_channo);
if (pos->spanno <= spanno) {
if (basechan < next_channo + pos->channels) {
/* Requested basechan breaks channel sorting */
- dev_notice(span->parent->dev.parent,
+ dev_notice(span_device(span),
"[%d] basechan (%d) is too low for wanted span %d\n",
local_spanno(span), basechan, spanno);
return -EINVAL;
@@ -6771,13 +6776,13 @@
break;
/* Cannot fit the span into the requested location. Abort. */
- dev_notice(span->parent->dev.parent,
+ dev_notice(span_device(span),
"cannot fit span %d (basechan=%d) into requested location\n",
spanno, basechan);
return -EINVAL;
}
- dahdi_dev_dbg(ASSIGN, span->parent->dev.parent,
+ dahdi_dev_dbg(ASSIGN, span_device(span),
"good: spanno=%d, basechan=%d (span->channels=%d)\n",
spanno, basechan, span->channels);
set_spanno_and_basechan(span, spanno, basechan);
@@ -6876,7 +6881,7 @@
return -EFAULT;
if (test_bit(DAHDI_FLAGBIT_REGISTERED, &span->flags)) {
- dev_notice(span->parent->dev.parent,
+ dev_notice(span_device(span),
"local span %d is already assigned span %d "
"with base channel %d\n", local_spanno(span), span->spanno,
span->chans[0]->channo);
@@ -6887,7 +6892,7 @@
span->ops->disable_hw_preechocan) {
if ((NULL == span->ops->enable_hw_preechocan) ||
(NULL == span->ops->disable_hw_preechocan)) {
- dev_notice(span->parent->dev.parent,
+ dev_notice(span_device(span),
"span with inconsistent enable/disable hw_preechocan");
return -EFAULT;
}
@@ -7091,7 +7096,7 @@
unsigned long flags;
if (!test_bit(DAHDI_FLAGBIT_REGISTERED, &span->flags)) {
- dev_info(span->parent->dev.parent,
+ dev_info(span_device(span),
"local span %d is already unassigned\n",
local_spanno(span));
return -EINVAL;
Modified: linux/trunk/drivers/dahdi/dahdi-sysfs.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/dahdi-sysfs.c?view=diff&rev=10449&r1=10448&r2=10449
==============================================================================
--- linux/trunk/drivers/dahdi/dahdi-sysfs.c (original)
+++ linux/trunk/drivers/dahdi/dahdi-sysfs.c Wed Jan 25 15:18:00 2012
@@ -799,10 +799,17 @@
{
int ret;
struct device *const dev = &ddev->dev;
+ const char *dn;
dev->parent = parent;
dev->bus = &dahdi_device_bus;
- dev_set_name(dev, "%s:%s", parent->bus->name, dev_name(parent));
+ dn = dev_name(dev);
+ if (!dn || !*dn) {
+ /* Invent default name based on parent */
+ if (!parent)
+ return -EINVAL;
+ dev_set_name(dev, "%s:%s", parent->bus->name, dev_name(parent));
+ }
ret = device_add(dev);
return ret;
}
More information about the dahdi-commits
mailing list