From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoqZ0-0002lm-Fj for qemu-devel@nongnu.org; Mon, 26 May 2014 04:47:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WoqYs-0002ar-2n for qemu-devel@nongnu.org; Mon, 26 May 2014 04:47:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32595) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoqYr-0002ac-Pm for qemu-devel@nongnu.org; Mon, 26 May 2014 04:47:14 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4Q8lD5a031799 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 26 May 2014 04:47:13 -0400 From: Gerd Hoffmann Date: Mon, 26 May 2014 10:47:01 +0200 Message-Id: <1401094027-5275-5-git-send-email-kraxel@redhat.com> In-Reply-To: <1401094027-5275-1-git-send-email-kraxel@redhat.com> References: <1401094027-5275-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PULL 04/10] usb-mtp: use bool to track MTPObject init status List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , "Dr. David Alan Gilbert" Stop setting nchildren to -1. Use separate bool variable to track whenever we've already fetched the child objects instead. Also make nchildren unsigned. Cc: Dr. David Alan Gilbert Signed-off-by: Gerd Hoffmann --- hw/usb/dev-mtp.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 943f930..c2750e4 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -109,7 +109,8 @@ struct MTPObject { struct stat stat; MTPObject *parent; MTPObject **children; - int32_t nchildren; + uint32_t nchildren; + bool have_children; QTAILQ_ENTRY(MTPObject) next; }; @@ -273,7 +274,6 @@ static MTPObject *usb_mtp_object_alloc(MTPState *s, uint32_t handle, o->handle = handle; o->parent = parent; o->name = g_strdup(name); - o->nchildren = -1; if (parent == NULL) { o->path = g_strdup(name); } else { @@ -340,7 +340,11 @@ static void usb_mtp_object_readdir(MTPState *s, MTPObject *o) struct dirent *entry; DIR *dir; - o->nchildren = 0; + if (o->have_children) { + return; + } + o->have_children = true; + dir = opendir(o->path); if (!dir) { return; @@ -789,9 +793,7 @@ static void usb_mtp_command(MTPState *s, MTPControl *c) c->trans, 0, 0, 0); return; } - if (o->nchildren == -1) { - usb_mtp_object_readdir(s, o); - } + usb_mtp_object_readdir(s, o); if (c->code == CMD_GET_NUM_OBJECTS) { trace_usb_mtp_op_get_num_objects(s->dev.addr, o->handle, o->path); nres = 1; -- 1.8.3.1