Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp678735pxb; Tue, 5 Apr 2022 18:26:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmBSiSUDOfaKShpVG8oOcoonrpQClKCsPefb/go6klXfSpn5Sw/O6nRQuCgrJiyuzpN9g0 X-Received: by 2002:a17:907:8a1b:b0:6e7:681e:b4b1 with SMTP id sc27-20020a1709078a1b00b006e7681eb4b1mr6144125ejc.392.1649208371075; Tue, 05 Apr 2022 18:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649208371; cv=none; d=google.com; s=arc-20160816; b=dSgjWMPdATAVWfqFoBlmCF8wdMX+t5db+3Z8sStKPAVlslIYJyTq0RsPML69t31FAK fm+isrpxwvzBTi+v724xYxbxcWjM6g4zIiPtKYNEPo9iTCZzJ2x4H46DR0YH6hSsIzYI DbOOylfn/m9Mo46YPfbpPxRE95LuqiZ3b1+826apHm3SVaLWeS/Pe37+3V96atzxz3DW eKyxoj6KdfAtLos1D1V202brDin6O3XIGo1VAaiQU+6f1IgM0dcqBWslcFCSPvei+HMa wLsoqKcrlPeDDvDltnlmH6TG4mFS6qEGt1zr4fEsFAjmsVCAdcYDRAaSeDWtR9AqZldy 6DJA== 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=jYeo8vgunRxvwfFWXiA56EPrm1LbGzDICJUmtZhPvbmfFAComxjG/O8rgU7gEneVaK RV8QUEDfi6SCIffJPyIwQ7ZTDoRl+RzzOG/jtM4ZvY+eDwyuTbGUZxc9A61PQ8xFMTFO z9hCEAKcjAGCQ9c83ws0xZFtdtmmfAWVBevAz3wztnLGfZLy+2ul9BPhOIcdZGRC+A0+ WQVAoQCU6ek4EidF3p+EcuoQYO3adiwViCGoRMJoeWXMX1Ocp27l2q8nFHhFX9wsw5r6 BfQHkNXBN59oY6brYaDSJhMWi7NaXXVfhGS/NOK7VxNuNRjGQKYymSA+YcKzk8Kz5iM1 6t4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nrknhYeZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020aa7d949000000b00418c2b5beabsi10417976eds.397.2022.04.05.18.25.43; Tue, 05 Apr 2022 18:26:11 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nrknhYeZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357440AbiDELz5 (ORCPT + 99 others); Tue, 5 Apr 2022 07:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244960AbiDEIwv (ORCPT ); Tue, 5 Apr 2022 04:52:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B86121C12B; Tue, 5 Apr 2022 01:47:57 -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 5406361504; Tue, 5 Apr 2022 08:47:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62364C385A0; Tue, 5 Apr 2022 08:47:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649148476; bh=sRY6U65i0znfe3KehcP3ZybCJpLi0ibCWb/vy8ikJbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nrknhYeZLJUk6Wo6kgfnbjXsgsQGiY1oDGUJowHtcd5XFCAmWehzkpbXqmr5vMsGI PtaQEBFF24A1aZnvOUqqar5md8qmwIwfY05cYbiOA5urMv1QnEO1NKG5IgVtA374o1 T/ztW3QyrShJKa5SGEinzskkAYdo7obFY2ZnQYtA= 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.16 0369/1017] media: vidtv: Check for null return of vzalloc Date: Tue, 5 Apr 2022 09:21:22 +0200 Message-Id: <20220405070405.238860696@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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