Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1002522pxb; Wed, 6 Apr 2022 06:28:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+GtGxoVi7JX/ZGECEEioGS5P+HKkQxc+pTnfb1xFwyzp6/i3ljugIseQctM5w6Dn9ujLX X-Received: by 2002:a17:903:40cd:b0:154:abdd:929d with SMTP id t13-20020a17090340cd00b00154abdd929dmr8828603pld.96.1649251714602; Wed, 06 Apr 2022 06:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649251714; cv=none; d=google.com; s=arc-20160816; b=Bkt75KfRDJnBDv9nHnFdYYXNxJ2Zs80K5FcQqwZ9lW9H0RAafr87VEMg1TKKsPmtC7 oLFKx17k4kKAfinmp5NLjIZzM7yPwvtOzj6uhhhWtEKzshse6IxOJjk6mYPtxqV71pce iYwfi+tzQNMh8Z3qBGJafuzubKZVIMwCPRdCcNkYOw5IuzbSRkTuYneoNib1b1KyhIOj lfAbtMoDc7na0GCIV0DP96B5FvHZ2sfXTpTO97VbdDSJhGq5wfHUA+HHC3ddWNAEYVuQ kFxnJUYH8BF3EIdNURZYR42BRRw4eihPolOgCcFb/qJdMGD53EErNm3WJ1X1E2mG9vYO v5/A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=C5DIqS9bxv14CnU6oa6NwJG5JYjXOHVaJakjgvyDuLM=; b=KtnIS3YIeVrwmWB7wMvXGX/mLBAZVfjvbbZvOZAx/nOvRQFe0+sZPSbx5Rh1h4Z6/u H+f38nHBMkmrxprmsY7dll/E7Y+orl7oUhG3EjCvW2TBxmUQlU9lRnHOMK6FNzy/sLbJ eoz23zz6Xvjnby3dFtqnQfhTP663ScCOW931Wz/drwvIB2xVKJ8+UU313mepua/ivSla zJ5PhmdHJwW3EkNY1f65JDZift7jkEqoL2A50MUZk+mGPMr6w9YA1npyPvWsYrDXlwmp gqmVoR4fxj6ltCol2kc1VEU6vagAR/w8NDhATyP9kwsz612CXgzsPiV8YySFUKQ/oUVV +jFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=u9NShTVa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b21-20020a6567d5000000b003816043ee5dsi3147339pgs.82.2022.04.06.06.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 06:28:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=u9NShTVa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E5EA530B974; Wed, 6 Apr 2022 04:06:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1456162AbiDEWpZ (ORCPT + 99 others); Tue, 5 Apr 2022 18:45:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348561AbiDEJsB (ORCPT ); Tue, 5 Apr 2022 05:48:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A812D54BF4; Tue, 5 Apr 2022 02:34:12 -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 21D186165C; Tue, 5 Apr 2022 09:34:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3308EC385A2; Tue, 5 Apr 2022 09:34:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151251; bh=sRY6U65i0znfe3KehcP3ZybCJpLi0ibCWb/vy8ikJbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u9NShTVauaivS0he+zx9sOdYQ4ynq7XTdsmpfBd0UYy9tc1ujIeWiLnStJpT6o8DI iXztpwufvYQ6CaCiW77S/WGjOfmMg1b6zQvrPc+Ift71GzfYdaP2u6Oo2K1rd+VYDS P6xezOwol1ymcEpdcedJJlZHpmGp8LMcA2uBvPwM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiasheng Jiang , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.15 348/913] media: vidtv: Check for null return of vzalloc Date: Tue, 5 Apr 2022 09:23:30 +0200 Message-Id: <20220405070350.277355877@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Jiasheng Jiang [ Upstream commit e6a21a14106d9718aa4f8e115b1e474888eeba44 ] As the possible failure of the vzalloc(), e->encoder_buf might be NULL. Therefore, it should be better to check it in order to guarantee the success of the initialization. If fails, we need to free not only 'e' but also 'e->name'. Also, if the allocation for ctx fails, we need to free 'e->encoder_buf' else. Fixes: f90cf6079bf6 ("media: vidtv: add a bridge driver") Signed-off-by: Jiasheng Jiang Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/test-drivers/vidtv/vidtv_s302m.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/media/test-drivers/vidtv/vidtv_s302m.c b/drivers/media/test-drivers/vidtv/vidtv_s302m.c index d79b65854627..4676083cee3b 100644 --- a/drivers/media/test-drivers/vidtv/vidtv_s302m.c +++ b/drivers/media/test-drivers/vidtv/vidtv_s302m.c @@ -455,6 +455,9 @@ struct vidtv_encoder e->name = kstrdup(args.name, GFP_KERNEL); e->encoder_buf = vzalloc(VIDTV_S302M_BUF_SZ); + if (!e->encoder_buf) + goto out_kfree_e; + e->encoder_buf_sz = VIDTV_S302M_BUF_SZ; e->encoder_buf_offset = 0; @@ -467,10 +470,8 @@ struct vidtv_encoder e->is_video_encoder = false; ctx = kzalloc(priv_sz, GFP_KERNEL); - if (!ctx) { - kfree(e); - return NULL; - } + if (!ctx) + goto out_kfree_buf; e->ctx = ctx; ctx->last_duration = 0; @@ -498,6 +499,14 @@ struct vidtv_encoder e->next = NULL; return e; + +out_kfree_buf: + kfree(e->encoder_buf); + +out_kfree_e: + kfree(e->name); + kfree(e); + return NULL; } void vidtv_s302m_encoder_destroy(struct vidtv_encoder *e) -- 2.34.1