From patchwork Thu Nov 25 15:04:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 31669 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp850642iob; Thu, 25 Nov 2021 07:07:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxCz/Shc6uSkXJoozWoAlXwqNevfyYZmlOrF/HcpfgsCZolqkyoPVgi+Tt4Huh1IvBOwEO X-Received: by 2002:a17:907:1687:: with SMTP id hc7mr31891861ejc.232.1637852829735; Thu, 25 Nov 2021 07:07:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637852829; cv=none; d=google.com; s=arc-20160816; b=lWh/C1JuKRzhWBKoubWXKL5sgAGftZlNgBWL62UvxT1AdcaFweD8KibGnVoaEkDOal Vb2q+n9eRMQEF8vGwEnPah1uG5JfoWk7T41hoWEkNVjTuId0jTB8IIoDt+mJdEaU5b3H G48snYv+LphhTtlVcQMpaMBtATPJrkZLv79ycRD2ZfPISCY887F6Eeo0ahFihy7hIPjZ f441989OVtwGkt9qkzDuezFGPU+Jzk0KFujKqVjgSEVqEdTh8hDQ3fHSOb8DHfhUugJj sY/JeVxjSByW+RRzz7cLrNbyekqygq3mpoxfheURczwSd9l1vu2lGNtvhEZ+pxeoa6CG hUYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=2ZbX2rsY43eDoc0CSFJI5Aqt10I/mvf0vQu3LSGS8uI=; b=ZzpPycxzKoAHoJ7Ltw/SVqcsZjqCnSk2O0x6VcJ9ykOsAoWzEnl8g2vdBvdG59L0IB rHDeYDx0aAQoW3ctf3Yz9K04tANh8umLGcXhg9I85edJI1tOdezdu2aGTnw+LkNNWfUr La2dDglfryss3k7zLyNZTETLWgNuRPlPJtDR+peXzrW0W4GzlckEqs0cFJEjabLQSFeH u3fOQ/1W/KrT6SPISYOER9/jMSSgbXDbzk9Gcelrva9BCdTWeW9w+8Kr4TXga5GrS0rp I6o2maRt6MaXuNsG73IuJP7xYVWkiqw4VS4cVBmFLUzm0T+s54+vxnNPkP/5OEjOGnYl hYmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id du6si10170996ejc.161.2021.11.25.07.07.09; Thu, 25 Nov 2021 07:07:09 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 744BD68AEE9; Thu, 25 Nov 2021 17:05:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 56A0A68AE8D for ; Thu, 25 Nov 2021 17:05:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C6E78240511 for ; Thu, 25 Nov 2021 16:05:11 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id VGpATOCQsDTU for ; Thu, 25 Nov 2021 16:05:07 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 831492404FE for ; Thu, 25 Nov 2021 16:05:06 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id A8F543A0398; Thu, 25 Nov 2021 16:05:05 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 25 Nov 2021 16:04:53 +0100 Message-Id: <20211125150500.25040-2-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211125150500.25040-1-anton@khirnov.net> References: <20211125150500.25040-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/9] lavf/v4l2: do not use a context variable unnecessarily X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: v2mUjdDXJphJ fd is local to the loop iteration, it is better to store it on stack than modify the context. --- libavdevice/v4l2.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index b5997fba33..777867db86 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -1033,16 +1033,17 @@ static int v4l2_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_l return ret; } while ((entry = readdir(dir))) { + int fd = -1; char device_name[256]; if (!v4l2_is_v4l_dev(entry->d_name)) continue; snprintf(device_name, sizeof(device_name), "/dev/%s", entry->d_name); - if ((s->fd = device_open(ctx, device_name)) < 0) + if ((fd = device_open(ctx, device_name)) < 0) continue; - if (v4l2_ioctl(s->fd, VIDIOC_QUERYCAP, &cap) < 0) { + if (v4l2_ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0) { ret = AVERROR(errno); av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n", av_err2str(ret)); goto fail; @@ -1064,8 +1065,7 @@ static int v4l2_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_l &device_list->nb_devices, device)) < 0) goto fail; - v4l2_close(s->fd); - s->fd = -1; + v4l2_close(fd); continue; fail: @@ -1074,9 +1074,8 @@ static int v4l2_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_l av_freep(&device->device_description); av_freep(&device); } - if (s->fd >= 0) - v4l2_close(s->fd); - s->fd = -1; + if (fd >= 0) + v4l2_close(fd); break; } closedir(dir);