From patchwork Fri Jun 29 18:07:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 10497181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 16B27601C7 for ; Fri, 29 Jun 2018 18:07:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05163296E5 for ; Fri, 29 Jun 2018 18:07:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA05C296EC; Fri, 29 Jun 2018 18:07:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1F30296D5 for ; Fri, 29 Jun 2018 18:07:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753867AbeF2SHb (ORCPT ); Fri, 29 Jun 2018 14:07:31 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:39856 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752811AbeF2SHb (ORCPT ); Fri, 29 Jun 2018 14:07:31 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id F1B4727883E Message-ID: <02c613919fec816e1166823372c8f1d9c94a3488.camel@collabora.com> Subject: Re: [PATCH 1/2] v4l-helpers: Don't close the fd in {}_s_fd From: Ezequiel Garcia To: Hans Verkuil , linux-media@vger.kernel.org Date: Fri, 29 Jun 2018 15:07:23 -0300 In-Reply-To: <6b727801-5055-928d-4005-39caaf09200f@xs4all.nl> References: <20180628192557.22966-1-ezequiel@collabora.com> <6b727801-5055-928d-4005-39caaf09200f@xs4all.nl> Organization: Collabora X-Mailer: Evolution 3.28.2-1 Mime-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hey Hans, On Fri, 2018-06-29 at 09:03 +0200, Hans Verkuil wrote: > On 06/28/2018 09:25 PM, Ezequiel Garcia wrote: > > When creating a second node via copy or assignment: > > > > node2 = node > > > > The node being assigned to, i.e. node2, obtains the fd. > > This causes a later call to node2.media_open to close() > > the fd, thus unintendenly closing the original node fd, > > via the call path (e.g. for media devices): > > > > node2.media_open > > v4l_media_open > > v4l_media_s_fd > > > > Similar call paths apply for other device types. > > Fix this by removing the close in xxx_s_fd. > > I fixed this in a different way by overloading the assignment > operator > and calling dup(fd). That solves this as well. > This patch is also needed to prevent the compliance tool from unintendenly closing a descriptor. static inline ssize_t v4l_wrap_read(struct v4l_fd *f, void *buffer, size_t n) Regards, Eze diff --git a/utils/common/v4l-helpers.h b/utils/common/v4l-helpers.h index 27683a3d286d..45ed997379a1 100644 --- a/utils/common/v4l-helpers.h +++ b/utils/common/v4l-helpers.h @@ -118,7 +118,11 @@ static inline int v4l_wrap_open(struct v4l_fd *f, const char *file, int oflag, . static inline int v4l_wrap_close(struct v4l_fd *f) { - return close(f->fd); + int ret; + + ret = close(f->fd); + f->fd = -1; + return ret; }