From patchwork Mon Oct 17 14:46:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 3491 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1492511wrs; Mon, 17 Oct 2022 07:54:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5pJUXw/lyf6GQ5RJr9BLcDqyQo+hI219GIUzpXk+CXX1c4hxqhvlsBxuLrNFhR7jvurkoi X-Received: by 2002:a50:fc85:0:b0:458:e7c6:1cfa with SMTP id f5-20020a50fc85000000b00458e7c61cfamr10853896edq.256.1666018467754; Mon, 17 Oct 2022 07:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666018467; cv=none; d=google.com; s=arc-20160816; b=NnY1EaVbgGwQZ1VVgtwCtjs2aQGz8WPN6JliDaSkLJCKJU7ZFQ984sXfh9hfK/VRK+ Up+BQPkaE5Khed+KpjTKRIjb+OHBf3dHYCpea6jUAUnDSgX/Ej11Vpi9l4ZkY/Zwlf7/ /GZhEJDJxftOWIQhPZ1hjWlFk3vCdTMAIQIry0do8ZKw/eng+asDj5mkop5zk4A6mf59 uEsHkdtXt0rweNrgdjvT1F2qTM0TkQYbzgRzyfNYW+74uYv4wfzyyEyFKZ7E3sPtmM1T BrgStjNTBn4ajEj2PbvAq1Z/o0EoieRy8u61d6ye7dnf7562Mkjrldh6BtNSKpaB4mhd 0TaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=FaLkMLMnSIhoYvqJJgNBDkifdbLoYx0RKTJ9nWcwiLI=; b=wWrOyt9O+PEa3/8ZG3KmoG0dGBhYw1t3XR1PT66FhbqVG9RTnXSbKHfCC3Ifw0ixoo Mwd+cF0KFbaKJSv6EQ+N271epQHDz9vHhn4yxcILsm26SPCfLyAJOG7pvvph0+rs2owU gp+p5jHGY3OBGWrrSUD3mYu6Cq8dGhkewHwWT1fD+Vkrg4ceoeBzDh+5U/GAledSRgV6 kKkPXnVxm1htHSJlYHhDWNUN9QVlF9a2PgH+82Fr2xIJ5VKHdHvKebxd2stGNmE6Ty8D iZhn59G//YpjB7DBUGU9X2wp3oJupMbtMQdsgh6gH7x8Gdd/hIN9dAcZumDvRnKsgV+O YXMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g15-20020a1709065d0f00b007306ac0faa0si9762939ejt.615.2022.10.17.07.54.02; Mon, 17 Oct 2022 07:54:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231143AbiJQOqp (ORCPT + 99 others); Mon, 17 Oct 2022 10:46:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230053AbiJQOqf (ORCPT ); Mon, 17 Oct 2022 10:46:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9921C36DF5; Mon, 17 Oct 2022 07:46:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DF03C6118F; Mon, 17 Oct 2022 14:46:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 900DFC433D7; Mon, 17 Oct 2022 14:46:32 +0000 (UTC) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Hans Verkuil Subject: [PATCH for 6.1 2/4] vivid: dev->bitmap_cap wasn't freed in all cases Date: Mon, 17 Oct 2022 16:46:26 +0200 Message-Id: <20221017144628.489271-3-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221017144628.489271-1-hverkuil-cisco@xs4all.nl> References: <20221017144628.489271-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746946980530446617?= X-GMAIL-MSGID: =?utf-8?q?1746946980530446617?= Whenever the compose width/height values change, the dev->bitmap_cap vmalloc'ed array must be freed and dev->bitmap_cap set to NULL. This was done in some places, but not all. This is only an issue if overlay support is enabled and the bitmap clipping is used. Signed-off-by: Hans Verkuil Fixes: ef834f7836ec ([media] vivid: add the video capture and output parts) --- .../media/test-drivers/vivid/vivid-vid-cap.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/media/test-drivers/vivid/vivid-vid-cap.c b/drivers/media/test-drivers/vivid/vivid-vid-cap.c index e3e78b5bd227..d52d24b61d34 100644 --- a/drivers/media/test-drivers/vivid/vivid-vid-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-vid-cap.c @@ -453,6 +453,12 @@ void vivid_update_format_cap(struct vivid_dev *dev, bool keep_controls) tpg_reset_source(&dev->tpg, dev->src_rect.width, dev->src_rect.height, dev->field_cap); dev->crop_cap = dev->src_rect; dev->crop_bounds_cap = dev->src_rect; + if (dev->bitmap_cap && + (dev->compose_cap.width != dev->crop_cap.width || + dev->compose_cap.height != dev->crop_cap.height)) { + vfree(dev->bitmap_cap); + dev->bitmap_cap = NULL; + } dev->compose_cap = dev->crop_cap; if (V4L2_FIELD_HAS_T_OR_B(dev->field_cap)) dev->compose_cap.height /= 2; @@ -913,6 +919,8 @@ int vivid_vid_cap_s_selection(struct file *file, void *fh, struct v4l2_selection struct vivid_dev *dev = video_drvdata(file); struct v4l2_rect *crop = &dev->crop_cap; struct v4l2_rect *compose = &dev->compose_cap; + unsigned orig_compose_w = compose->width; + unsigned orig_compose_h = compose->height; unsigned factor = V4L2_FIELD_HAS_T_OR_B(dev->field_cap) ? 2 : 1; int ret; @@ -1029,17 +1037,17 @@ int vivid_vid_cap_s_selection(struct file *file, void *fh, struct v4l2_selection s->r.height /= factor; } v4l2_rect_map_inside(&s->r, &dev->fmt_cap_rect); - if (dev->bitmap_cap && (compose->width != s->r.width || - compose->height != s->r.height)) { - vfree(dev->bitmap_cap); - dev->bitmap_cap = NULL; - } *compose = s->r; break; default: return -EINVAL; } + if (dev->bitmap_cap && (compose->width != orig_compose_w || + compose->height != orig_compose_h)) { + vfree(dev->bitmap_cap); + dev->bitmap_cap = NULL; + } tpg_s_crop_compose(&dev->tpg, crop, compose); return 0; }