Re: [PATCH 3/5] pylibfdt: Fix comparison of return value.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Hello.

On 07/16/2018 01:33 AM, Simon Glass wrote:
Hi,

On 12 July 2018 at 19:01, David Gibson <david@xxxxxxxxxxxxxxxxxxxxx> wrote:
On Thu, Jul 12, 2018 at 04:10:43PM +0200, frenzy@xxxxxxxxx wrote:
From: Lumir Balhar <lbalhar@xxxxxxxxxx>

In Python 2, an empty list is always higher than zero but in
Python 3 these types cannot be compared.
It would be helpful to add in the commit message what the case is
where this is passed a non-integer value.
I suspect this is next_node(). It looks like I added this in without
noticing that check_err() is not correct in this case. It is not
designed to be called with a list.
Yes it is. There is a few cases in testsuite which result to check_err() call with a list as a first argument.

I removed my change from check_err() and add type checking to next_node().

Is it okay now?

If that is the culprit, can we instead change next_node() to call
check_err the first item of the tuple?

Signed-off-by: Lumir Balhar <lbalhar@xxxxxxxxxx>
---
  pylibfdt/libfdt.i | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
index 88d443d..9c0dcdc 100644
--- a/pylibfdt/libfdt.i
+++ b/pylibfdt/libfdt.i
@@ -124,7 +124,7 @@ def check_err(val, quiet=()):
      Raises
          FdtException if val < 0
      """
-    if val < 0:
+    if isinstance(val, int) and val < 0:
          if -val not in quiet:
              raise FdtException(val)
      return val
--
David Gibson                    | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
                                 | _way_ _around_!
http://www.ozlabs.org/~dgibson
Regards,
Simon

>From 97d28e33fab93fab2246a9fe8aeb9e66b3b24899 Mon Sep 17 00:00:00 2001
From: Lumir Balhar <lbalhar@xxxxxxxxxx>
Date: Mon, 9 Jul 2018 12:41:13 +0200
Subject: [PATCH 3/5] pylibfdt: check_err accepts only integer as a first
 argument.

next_node() should not pass list as an first argument to
check_err() function.

Signed-off-by: Lumir Balhar <lbalhar@xxxxxxxxxx>
---
 pylibfdt/libfdt.i | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
index 3e25430..193518f 100644
--- a/pylibfdt/libfdt.i
+++ b/pylibfdt/libfdt.i
@@ -137,7 +137,7 @@ def check_err(val, quiet=()):
     Raises
         FdtException if val < 0
     """
-    if val < 0:
+    if isinstance(val, int) and val < 0:
         if -val not in quiet:
             raise FdtException(val)
     return val
@@ -211,7 +211,10 @@ class FdtRo(object):
         Raises:
             FdtException if no more nodes found or other error occurs
         """
-        return check_err(fdt_next_node(self._fdt, nodeoffset, depth), quiet)
+        result = fdt_next_node(self._fdt, nodeoffset, depth)
+        if isinstance(result, list):
+            return check_err(result[0], quiet)
+        return check_err(result, quiet)
 
     def first_subnode(self, nodeoffset, quiet=()):
         """Find the first subnode of a parent node
-- 
2.17.1


[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux