Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1683628rwb; Wed, 16 Nov 2022 23:49:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf4mpDlgKRmGN89OLZInrjbY7adMltyypWqale7BMv4MzsZzR9w66nUfgPUFS53CGs9F0sks X-Received: by 2002:a05:6a00:2c87:b0:562:e790:dfe0 with SMTP id ef7-20020a056a002c8700b00562e790dfe0mr1864673pfb.16.1668671369845; Wed, 16 Nov 2022 23:49:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668671369; cv=none; d=google.com; s=arc-20160816; b=0LSoaQ7nahass1b2zjCIFW+tO5lhGBcG4lb2ufDndJw7DNNnvy6MLdmeEbwq7qH0kc F1ILl753qtphSBS0q8+ZyyENAuhXTDUZI3PkPhjh89sAUaQ1IVLT0I6IC0aQzANI06GO bOkiAwIoSgS+/KblfFPBsR9Srb3rEmsM8rMqDubqTZ+iLuzfmWiEnkDcbXLIfs4mR06U 2TdfFBtjNUiYXEHyjnTK3jjP6g5oUlkmg829/33zDY6wGje3eAw+82ppPxqalYf+MW6p ejB2SjHUK31qzLNlRpmkZezkkYDWEcMcTJQCMUTV3nR3U/wEw5TzmX+KwDwp/LviSakX UErg== 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; bh=2ZfrNIS6WfOgimgV3nOtdum8SrvzbGOibMVRqxma3d0=; b=RzWJ01dpV5fsXAcTOWYoC1cD/0u7Ht5BObRhCam0aUxtxMDg2AF6OUSvC2NlsG7PmF sATWkJC1pwwzw5BFVtALlwsxOQfYveNyGBjDzSri+laKQVmwVzkpc2JHKKfa4e97ZKfT 6sQqJsLi3hMY5Bj1nDi8iVIWS0aTHwPjfI6WJndTqns+ZFlECte/XfGwCeyH+z59RTuT wfGmcHGoYwNiWh3I5PbN32YDmtFtoeJpg8ekpm1/qJ8NPxGLkKCAmh7UHMk7wRzkjzBr ADSO7UARq/5JjGaXXtMSpn+cpPCwvE3+fRAGQlQfkIGP/ilLGYwzQmFmOTfcJrk3jA14 WhWA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jj13-20020a170903048d00b001868a61d507si347674plb.180.2022.11.16.23.49.18; Wed, 16 Nov 2022 23:49:29 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234303AbiKQHCr (ORCPT + 91 others); Thu, 17 Nov 2022 02:02:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231562AbiKQHCp (ORCPT ); Thu, 17 Nov 2022 02:02:45 -0500 X-Greylist: delayed 342 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 16 Nov 2022 23:02:44 PST Received: from cstnet.cn (smtp21.cstnet.cn [159.226.251.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3D7396EB5C; Wed, 16 Nov 2022 23:02:43 -0800 (PST) Received: from localhost.localdomain (unknown [124.16.138.125]) by APP-01 (Coremail) with SMTP id qwCowACXNmiN3HVjEDojCg--.6856S2; Thu, 17 Nov 2022 15:02:37 +0800 (CST) From: Jiasheng Jiang To: p.zabel@pengutronix.de, mchehab@kernel.org Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH] media: coda: Add check for kmalloc Date: Thu, 17 Nov 2022 15:02:36 +0800 Message-Id: <20221117070236.44632-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: qwCowACXNmiN3HVjEDojCg--.6856S2 X-Coremail-Antispam: 1UD129KBjvJXoW7CFW8tw45JFy5Cw43tr1fZwb_yoW8Jw48pF W3Ar92yrWrGw1v9FWDJ3yxZas8ua4ftFWUGFy7uwn5CwsxWr40qFyjqay5tF1UArZ5CFyj yFs8t3y5CF4UAFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkv14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r xl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj 6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr 0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVAFwVW8 CwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r 1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij 64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr 0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF 0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUfpnQUUUUU= X-Originating-IP: [124.16.138.125] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,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 As the kmalloc may return NULL pointer, it should be better to check the return value in order to avoid NULL poineter dereference, same as the others. Fixes: cb1d3a336371 ("[media] coda: add CODA7541 JPEG support") Signed-off-by: Jiasheng Jiang --- drivers/media/platform/chips-media/coda-bit.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/chips-media/coda-bit.c b/drivers/media/platform/chips-media/coda-bit.c index 2736a902e3df..240bdbc64785 100644 --- a/drivers/media/platform/chips-media/coda-bit.c +++ b/drivers/media/platform/chips-media/coda-bit.c @@ -1084,10 +1084,16 @@ static int coda_start_encoding(struct coda_ctx *ctx) } if (dst_fourcc == V4L2_PIX_FMT_JPEG) { - if (!ctx->params.jpeg_qmat_tab[0]) + if (!ctx->params.jpeg_qmat_tab[0]) { ctx->params.jpeg_qmat_tab[0] = kmalloc(64, GFP_KERNEL); - if (!ctx->params.jpeg_qmat_tab[1]) + if (!ctx->params.jpeg_qmat_tab[0]) + return -ENOMEM; + } + if (!ctx->params.jpeg_qmat_tab[1]) { ctx->params.jpeg_qmat_tab[1] = kmalloc(64, GFP_KERNEL); + if (!ctx->params.jpeg_qmat_tab[1]) + return -ENOMEM; + } coda_set_jpeg_compression_quality(ctx, ctx->params.jpeg_quality); } -- 2.25.1