Skip to content

Commit

Permalink
Devicetree: edtlib: fix possible AttributeError in Property.description
Browse files Browse the repository at this point in the history
Attempting to access the property Property.description
when Property.spec.description is None would raise
AttributeError: 'NoneType' object has no attribute 'strip'.

Known properties that may not have a description
(Property.spec.description is None):
- 'compatible' for nodes such as / /soc /soc/timer@e000e010 /leds /pwmleds
- 'reg'        for nodes such as /soc/timer@e000e010
- 'status'     for nodes such as /soc/timer@e000e010
- 'gpios'      for nodes such as /leds/led_0 /buttons/button_0
- 'pwms'       for nodes such as /pwmleds/pwm_led_0

This patch checks the PropertySpec.description attribute before calling
strip(): will return None, and not raise AttributeError.

Signed-off-by: Chris Duf <chris@openmarl.org>

Co-authored-by: Gerard Marull-Paretas <gerard@teslabs.com>
  • Loading branch information
2 people authored and stephanosio committed Oct 13, 2022
1 parent 2530ba5 commit 230c80e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scripts/dts/python-devicetree/src/devicetree/edtlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1610,8 +1610,8 @@ class Property:
Convenience for spec.name.
description:
Convenience for spec.name with leading and trailing whitespace
(including newlines) removed.
Convenience for spec.description with leading and trailing whitespace
(including newlines) removed. May be None.
type:
Convenience for spec.type.
Expand Down Expand Up @@ -1655,7 +1655,7 @@ def name(self):
@property
def description(self):
"See the class docstring"
return self.spec.description.strip()
return self.spec.description.strip() if self.spec.description else None

@property
def type(self):
Expand Down

0 comments on commit 230c80e

Please sign in to comment.