Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3256071pxf; Mon, 15 Mar 2021 05:35:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3jf7YWcMfLW3kfkC0nIjLowyFCsHaFB3Za6oDHODWZcXcRp1bef3Este5RcfJ7ec+wDKp X-Received: by 2002:aa7:c7d5:: with SMTP id o21mr28905376eds.166.1615811752840; Mon, 15 Mar 2021 05:35:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615811752; cv=none; d=google.com; s=arc-20160816; b=sXME6FkuazW/5oQNL25XTOpHHYHlIb10wMiu16U6qlhC0sXVkv+hGdRQAcS2kFFE5d 0F+t3inkZT7VbCaxLn0/KLe6r8dap6t5mYxuFtZAPy7UWN4ucghC2NMYU7dylprY+DtU UVoSEE0foGb7C483uDJbKs/vCOUm5pSJe3hmKDFL/C/SDV7WIr2Mn2trI78tiEVgW3RK +Oz78i9Mka6WpmeU0fLb9qAv0zHl6Ca0jgQnQbI+HzQ8CJcm+2hPh9XHy7DMS9o6DJxG O4CFiDle2h3PSCxlxTAP2+zjybuKCacoVVhjGHJqyzT4UJuIEBdvds00JGy9i3dh22VM RP7A== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=1xoa3G+ISwKSIeuqcwnTgZqAGyqpi/mTiJ1R03k5mAc=; b=MjwwI+RYvRN1nihfv8JVn/Ia/iBO3oSI/coVsbU4SkD3XZ/4mjJrEMZ2sOVHkCV2i2 x6jElYYpp+sfH4X6BvnJFE0i+2zmMtYq7/wZfO/fRRV65KeG3rsHAVYDrHAcYWuaSqSY tj+TNCzxIvUBOMisZPmCsYn8mAJb4Umt8/UJzJ4dDFnJSf3bB2HIj0AXhKrvviq1BW79 by3m/S9CvnlIWdZFGxY9yyaoXlsLMVInlQz0AzNa6C/twD9wKcCk1DcdWgdeKjaAKvvh d49rTHsBYRJ8bZXeFUW0ATicWvYduVuhwFY/hf+D6q5TT7qzR1ws4Dbd0Rh6PW0Iz/on LBKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=LVWU4ord; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j2si10504267ejv.381.2021.03.15.05.35.30; Mon, 15 Mar 2021 05:35:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=LVWU4ord; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbhCOMeg (ORCPT + 99 others); Mon, 15 Mar 2021 08:34:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbhCOMeL (ORCPT ); Mon, 15 Mar 2021 08:34:11 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D00C8C061574 for ; Mon, 15 Mar 2021 05:34:10 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id bm21so65868170ejb.4 for ; Mon, 15 Mar 2021 05:34:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1xoa3G+ISwKSIeuqcwnTgZqAGyqpi/mTiJ1R03k5mAc=; b=LVWU4ordRDJ4NugmIqMqf+p5Llh9f5FzvOIzFM4b15JxtT3XC0042nqDEoZatqLSoV JpFGPD0n2tJdGQDzDOGYjPBtfpFxAy5DMUzmjQ0cwHJn8jt9UCmSad/tFTVrJT4PZXCz LIaFZxddaQr9VAgYrOqJleg4s94tHuhXJS3m4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1xoa3G+ISwKSIeuqcwnTgZqAGyqpi/mTiJ1R03k5mAc=; b=UmteTtyk8YXIIwnpg7BLiJ6KUNh4guQvEPiN2RXwFjW7nk1LOa3MGsXHHMjueWNLQq QsSvq2a1hoYGo7eQEZ1A/+FF2L9M3mb5lRPJvilDiG35At61+eatgjh7vwbLUoQsxySV bk8hpBJvvwc0X4nNjygYOWA25nY9jtwMSMtidDdPswsfBpCIvWyk2OqeZ9dh3MQVpWYp ShAXKf2/jKFn7BPPM0BByvY1u6rYIDoXte0T926jR6fnvRyjhxJ6ceH0r/BjgymvFCNw nn1R9/fy+RyciqyyQFSG69sUvC6wLOLTTLHER1GUOwxkRgLweouqHEhj4258fpOD9Rus 4UOA== X-Gm-Message-State: AOAM533R08S8NL+1ReSYzhdwf0QH+/4kV0pUQ+0X8qiGc9VLprIQzQyl jNy0n/ZtWF+4Ze2lP/Pnm6iemg== X-Received: by 2002:a17:906:380b:: with SMTP id v11mr23826856ejc.183.1615811649657; Mon, 15 Mar 2021 05:34:09 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id p3sm7155128ejd.7.2021.03.15.05.34.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 05:34:09 -0700 (PDT) From: Ricardo Ribalda To: Sakari Ailus , Bingbu Cao , Tianshu Qiu , Mauro Carvalho Chehab , Greg Kroah-Hartman , Arnd Bergmann , linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda , stable@vger.kernel.org Subject: [PATCH v2 1/2] media: staging/intel-ipu3: Fix memory leak in imu_fmt Date: Mon, 15 Mar 2021 13:34:05 +0100 Message-Id: <20210315123406.1523607-1-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We are losing the reference to an allocated memory if try. Change the order of the check to avoid that. Cc: stable@vger.kernel.org Fixes: 6d5f26f2e045 ("media: staging/intel-ipu3-v4l: reduce kernel stack usage") Signed-off-by: Ricardo Ribalda --- drivers/staging/media/ipu3/ipu3-v4l2.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index 60aa02eb7d2a..35a74d99322f 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -693,6 +693,13 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, if (inode == IMGU_NODE_STAT_3A || inode == IMGU_NODE_PARAMS) continue; + /* CSS expects some format on OUT queue */ + if (i != IPU3_CSS_QUEUE_OUT && + !imgu_pipe->nodes[inode].enabled) { + fmts[i] = NULL; + continue; + } + if (try) { fmts[i] = kmemdup(&imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp, sizeof(struct v4l2_pix_format_mplane), @@ -705,10 +712,6 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, fmts[i] = &imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp; } - /* CSS expects some format on OUT queue */ - if (i != IPU3_CSS_QUEUE_OUT && - !imgu_pipe->nodes[inode].enabled) - fmts[i] = NULL; } if (!try) { -- 2.31.0.rc2.261.g7f71774620-goog