Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp275775rwb; Mon, 26 Sep 2022 18:49:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7UhBs4SkQ7SIa9tXDV4gEkVvGF12CKMXveJ9V8Xr4WlwYqRBgyCUn0DJSDvB/exuEi8CjW X-Received: by 2002:a05:6a00:1706:b0:547:3e11:9160 with SMTP id h6-20020a056a00170600b005473e119160mr26619632pfc.79.1664243388739; Mon, 26 Sep 2022 18:49:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664243388; cv=none; d=google.com; s=arc-20160816; b=VnbaVLunk7il+8/gqPLWhe4prnyU20C72UXo6Cj5gprTkxNbDlevy4foLtvKkx1+er l8UM93tep8Dm5atmMPUf/arSLIVIvAu39fMFnHOUEZxoaI2YCqRJbC/eMHZS5csC4Gqr ScLpXXXxytrNmYx5hI+Evh9rPhC/CySFRUQ6b0H0fNFP0Y+3lGNwy80D3lhbG2WRIaSw GzrNrl+BHGACNtCGWjGXWjC023gStTqj5s26N+g2jXVu/QDEGpQHjPu3Sr8E2iQEbzeZ UKqEXolJMY4WqTYGPVAQCBxZZ9TkG0PNGYbSBz9DsdqKe9mytuh1Kki0bS0VkHzJ+MiR 4BFg== 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=q7nrddTmx2Z+JOP7iknapyVZgqcP41MAtFPCh9jY2C4=; b=GEnjh0XfsHBbXvtwLHzxKT+aH/1LodpUKSIqgsfD2MVcVeKE8C2OhCAq2/uWAjQdGM kLB0l03nB5I53+ZdKszaIemVAfl7sD4+BfYeuFPWHuy5g6RQ1sGcTtJzfnLsM5Ro1cLX AyxeelnGFADVzYFTrIRHmjdWePXK3/cr3MrSrz7FXn7mpAlOQa75O6FsEZbjXrTr8Kzx LfqIqRxKvKK01b06O6YUH/9DjZroqem5jOzuqi7jH7WyqTvEaH8fnOO9FYyD9DioZgLb E6jNMFpo0+kWMnalMHG5aRm9BEpls1nFmL9FgOW9RSnrfgnpim7vTUxgE8upWt0D38O4 qVAw== 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 k2-20020a170902c40200b00175659beafcsi329879plk.189.2022.09.26.18.49.37; Mon, 26 Sep 2022 18:49:48 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229834AbiI0B2e (ORCPT + 99 others); Mon, 26 Sep 2022 21:28:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229509AbiI0B2c (ORCPT ); Mon, 26 Sep 2022 21:28:32 -0400 Received: from cstnet.cn (smtp84.cstnet.cn [159.226.251.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E9265A287F for ; Mon, 26 Sep 2022 18:28:30 -0700 (PDT) Received: from localhost.localdomain (unknown [124.16.138.125]) by APP-05 (Coremail) with SMTP id zQCowAAXCHWxUTJjVKE0Ag--.33020S2; Tue, 27 Sep 2022 09:28:19 +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: jpeg: Add check for kmalloc Date: Tue, 27 Sep 2022 09:28:13 +0800 Message-Id: <20220927012813.6097-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: zQCowAAXCHWxUTJjVKE0Ag--.33020S2 X-Coremail-Antispam: 1UD129KBjvJXoW7CFW8Cr4DAw48Gr4xAw4kCrg_yoW8GrWDpa yxAr9FkrWrGrnYvF1DJ3yxuF98u34FqFW8Gry7uw18Cw43Xr48XF1Uta45KF18AFZIkw15 AFZ8tw45CF17AFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkq14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr 1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv 7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r 1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE14v_ KwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r 1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij 64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr 0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF 0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7VUbYFAPUUUUU== X-Originating-IP: [124.16.138.125] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 kmalloc can return NULL pointer, it should be better to check the return value and return error, same as coda_jpeg_decode_header. Fixes: 96f6f62c4656 ("media: coda: jpeg: add CODA960 JPEG encoder support") Signed-off-by: Jiasheng Jiang --- drivers/media/platform/chips-media/coda-jpeg.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/chips-media/coda-jpeg.c b/drivers/media/platform/chips-media/coda-jpeg.c index a0b22b07f69a..2284e0420934 100644 --- a/drivers/media/platform/chips-media/coda-jpeg.c +++ b/drivers/media/platform/chips-media/coda-jpeg.c @@ -1053,10 +1053,16 @@ static int coda9_jpeg_start_encoding(struct coda_ctx *ctx) v4l2_err(&dev->v4l2_dev, "error loading Huffman tables\n"); return ret; } - 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); return 0; -- 2.25.1