From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44949) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XAc5Y-0004DO-Cv for qemu-devel@nongnu.org; Fri, 25 Jul 2014 05:47:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XAc5Q-0007eK-Th for qemu-devel@nongnu.org; Fri, 25 Jul 2014 05:46:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16634) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XAc5Q-0007bG-MJ for qemu-devel@nongnu.org; Fri, 25 Jul 2014 05:46:48 -0400 Message-ID: <1406281586.20767.3.camel@nilsson.home.kraxel.org> From: Gerd Hoffmann Date: Fri, 25 Jul 2014 11:46:26 +0200 In-Reply-To: <1406271172-1192-2-git-send-email-arei.gonglei@huawei.com> References: <1406271172-1192-1-git-send-email-arei.gonglei@huawei.com> <1406271172-1192-2-git-send-email-arei.gonglei@huawei.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 1/7] bootindex: add modify_boot_device_path function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: arei.gonglei@huawei.com Cc: peter.maydell@linaro.org, weidong.huang@huawei.com, mst@redhat.com, aik@ozlabs.ru, qemu-devel@nongnu.org, agraf@suse.de, dmitry@daynix.com, akong@redhat.com, armbru@redhat.com, lersek@redhat.com, marcel.a@redhat.com, somlo@cmu.edu, luonengjun@huawei.com, peter.huangpeng@huawei.com, alex.williamson@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, lcapitulino@redhat.com, rth@twiddle.net, kwolf@redhat.com, peter.crosthwaite@xilinx.com, Chenliang , imammedo@redhat.com, afaerber@suse.de Hi, > +void modify_boot_device_path(int32_t bootindex, DeviceState *dev, > + const char *suffix) > +{ > + FWBootEntry *node, *i; > + > + assert(dev != NULL || suffix != NULL); > + > + QTAILQ_FOREACH(i, &fw_boot_order, link) { > + if (i->bootindex == bootindex) { > + qerror_report(ERROR_CLASS_GENERIC_ERROR, > + "The bootindex %d has already been used", bootindex); > + return; > + } > + /* delete the same original dev */ > + if (i->dev->id && !strcmp(i->dev->id, dev->id)) { > + QTAILQ_REMOVE(&fw_boot_order, i, link); Ok ... > + g_free(i->suffix); > + g_free(i); ... but you should free the old entry later ... > + > + break; > + } > + } > + > + if (bootindex >= 0) { > + node = g_malloc0(sizeof(FWBootEntry)); > + node->bootindex = bootindex; > + node->suffix = g_strdup(suffix); ... because you can just copy the suffix from the old entry here, instead of expecting the caller pass it in. cheers, Gerd