Received: from eggs.gnu.org ([2001:4830:134:3::10]:41902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abCFW-0008AC-KI for qemu-devel@nongnu.org; Wed, 02 Mar 2016 14:15:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abCFR-0005Fv-Hf for qemu-devel@nongnu.org; Wed, 02 Mar 2016 14:15:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54074) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abCFR-0005Fb-Bq for qemu-devel@nongnu.org; Wed, 02 Mar 2016 14:15:49 -0500 From: Markus Armbruster References: <1456771254-17511-1-git-send-email-armbru@redhat.com> <1456771254-17511-22-git-send-email-armbru@redhat.com> <878u20j2qq.fsf@blackfin.pond.sub.org> Date: Wed, 02 Mar 2016 20:15:45 +0100 In-Reply-To: (=?utf-8?Q?=22Marc-Andr=C3=A9?= Lureau"'s message of "Wed, 2 Mar 2016 18:33:29 +0100") Message-ID: <87y4a0d732.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 21/38] ivshmem: Disentangle ivshmem_read() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Cc: Paolo Bonzini , cam , Claudio Fontana , QEMU , David Marchand Marc-Andr=C3=A9 Lureau writes: > On Wed, Mar 2, 2016 at 4:53 PM, Markus Armbruster wro= te: >>>> + if (msg =3D=3D -1) { >>>> + process_msg_shmem(s, fd); >>> >>> the previous code used to close fd if any, it's worth to keep that imho >> >> I'm blind. Where? > > Sorry, wrong place I looked at, seems you got them all. > > if (msg < -1 || msg > IVSHMEM_MAX_PEERS) { > error_report("server sent invalid message %" PRId64, msg); > close(fd); > return; > } > > > However, why not keep the if fd !=3D -1 here (not a great idea to call > close otherwise) We refuse to make the code more verbose to avoid free(NULL), and I very much agree with that. close(-1) is like free(NULL) in that it is perfectly safe. Where they differ is performance: free() checks for null right away, but close() checks only after switching to supervisor mode. Doesn't matter on an error path.