Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp920172pxp; Wed, 16 Mar 2022 21:20:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYi6ORU+9J0VZNj7jtqN3s6WfTw/PXmer1/5K1ItYzrR8Aqcq57hP8grFjZFZZUiBLAWTX X-Received: by 2002:a63:202:0:b0:37c:4cfc:b89f with SMTP id 2-20020a630202000000b0037c4cfcb89fmr2181317pgc.396.1647490825045; Wed, 16 Mar 2022 21:20:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647490825; cv=none; d=google.com; s=arc-20160816; b=kH3EP7m8pLTUX0FlXataoU309g7nnDsyh0c9JZXTjGptD0Uj/ZV3OFknrN5IzYhj1S 8rBhhx8kGGkfRyg/fft0ygBQKQmqG06yCFE1SvZGvrJ8+jYO/Bf88r16E5z01llEf6in YERrFe+O1mD5wC1bykyVpgOieP/sbBX91T/MMTlIxQwNdCLhsVHRHuq1HGOP2tj4vpiU My7B5C2ZgeL1r8zoFW8ZVP5N7LMq7DKkYPZbVH5XdmIKJ+uyJlsl69W1PiJJXIW2dwmC /34N3MYygXT8YQUCNhp6Og3Aw6kJ7Lrl603zK+AelRgX32i024WspvNx1qJvNkyta210 V6xA== 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:date :subject:cc:to:from:message-id:dkim-signature; bh=SpliapCVlfa+D7lo3BSKvVkGgWUYrJC2HluZ0dliScA=; b=L7P29A17PDGFrTFss60BafPwHdSruuWMeDMjbpOu0KvNA9TIVf2nClYQrT0huTKVRV 9fDMnrl1VmCrv5hJ9QFKqJgnFsOskRxqPpIgBWLIRil+NsNw+EajIPR0c/ouoVC3TU1B 0u7sbOe0/hR+6y5WCWno85Laax4PXFdd8zxNmcINJxXOba8t4s8/zz01cjJEHZYDj8B0 3XfODbZ56cCPF40PSAIda6HzyYno9mp54SIankCK7y+5gjobC8V8c7bUZhTxSpcQdebn Lo15uGo+M2PIIPfFRg09auz81x3dqOr27VLxvVZT9tKE/+RCwv/POrBXKO4rytBw4g4e jEcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=j1gUfUjv; 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=foxmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a18-20020a170902ecd200b00153dd685439si1674553plh.478.2022.03.16.21.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 21:20:25 -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=@foxmail.com header.s=s201512 header.b=j1gUfUjv; 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=foxmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B71F082D24; Wed, 16 Mar 2022 20:54:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350145AbiCOQlB (ORCPT + 99 others); Tue, 15 Mar 2022 12:41:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350140AbiCOQk7 (ORCPT ); Tue, 15 Mar 2022 12:40:59 -0400 Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C491B57169 for ; Tue, 15 Mar 2022 09:39:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1647362382; bh=SpliapCVlfa+D7lo3BSKvVkGgWUYrJC2HluZ0dliScA=; h=From:To:Cc:Subject:Date; b=j1gUfUjveD44+cikeEOvXTHgEEzZYSWXa/9Ey6IKnwyCTeWg1j+71vRFezMiSS/1D s30ULYiWLyh1clZSHN5iFQO+i2nHseuZUFhJbDslT+oUXyyVwZ5JEvfBICI929Vw4n fAaMkFCH3UQNEU3cSSfdxSEmr9ZQMHeFSCW4vgHA= Received: from localhost.localdomain ([43.227.138.48]) by newxmesmtplogicsvrsza8.qq.com (NewEsmtp) with SMTP id 9E6B06D9; Wed, 16 Mar 2022 00:39:38 +0800 X-QQ-mid: xmsmtpt1647362378te3kqnwz3 Message-ID: X-QQ-XMAILINFO: MyHh0PQai9FptZrresos5TGYovrAI+b46m/OEFalwsYWPXYAt4CGzqGpH4qHzf 2gZ+SVmeOSV+UivL+Bfa4Ikq2zTwtG+Z97smM5IdHLqkcNd+luPBz0Yb+eYpR7i0DFS3jCwESFsR m5tFS9SuWgxRbyJsQuBbym8kuCs7Cpwz3dW7XyK4yzc1hjTNFGwpRT25qBuMBFNIgOtrk4x/1Vsb ZfE4+seSM2vdiI69P51oSn4a0ocKVw44nJZgWtBWyrgbUzNerW7mhuNXY+QT+5f2oYZEBwq3FZtD hCJvQW7bb4mUKYry0ovwXK5UQO7v5NPbyHKtKFT0otiVgsp5TVOn4NO6snyt/0CkyDoFhfmgZw3U 6VK/Y0i6M5mbbfP70ZKhA5/7pCMXmZfs02vRHzEkqv2HOW5Zt3FnQ8+UlATL0O648en5Id8H69pv 42PRteqSxGASRIo9+7RB3ZJOgt+rEuhz01U9Mm17pZdCeSWvAmplhxrw9KbykJTmsK1Q8dBBFUD4 t0FuTeXnxskrXnGqAOueZRCQRoRnYrM/vnxqNRCLEeo1dIE9noBWe60UBs/AT+D0E+Dw/xODQ3by rN8ZQrtJpAJv3F6DXS5r02PiyqzoOdET3nEE7ksHV3DYjAMtniHgvCHgPqmtnl/BvC/zwZbbuG1C /Weayy7PbYKZwaExiDThhLoiardMm2W56CGXKv6dZQgj1yM5W9M+a7b9L61E0D1WFFvUHjzYec8t pNpZkzrB188Jj76LomGTLX6/I/0HqURM7XhpmTpapQ3gWHOs/wLpVBsDiHQkA55vH7Z16TxDs/L2 KVEUi1MmCoPBqc00STWVF+RDT2cCAdiF2uT1AA0W0wjo4ycMmGQ0JNtKdbw6Ih4B9v+IIsqsq2yo 2SHgxsLj0g+7SV+nMKJF0r7lWIVVCh29/UM8db5wANkZQ5ci1FFOnBS1KmqiukFGmurUnR3Cr3 From: xkernel.wang@foxmail.com To: gregkh@linuxfoundation.org, dan.carpenter@oracle.com, nsaenz@kernel.org Cc: bcm-kernel-feedback-list@broadcom.com, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Xiaoke Wang Subject: [PATCH v3] staging: mmal-vchiq: add a check for the return of vmalloc() Date: Wed, 16 Mar 2022 00:39:13 +0800 X-OQ-MSGID: <20220315163913.878-1-xkernel.wang@foxmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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: Xiaoke Wang vmalloc() is a memory allocation API which can return NULL when some internal memory errors happen. So it is better to check the return value of it to catch the error in time. Signed-off-by: Xiaoke Wang --- ChangeLog: v1->v2 jump to the proper location and remove redundant instruction. v2->v3 fix the mistake bring by version 2. drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c index 76d3f03..24cc0fe 100644 --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c @@ -1909,6 +1909,10 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance) mutex_init(&instance->vchiq_mutex); instance->bulk_scratch = vmalloc(PAGE_SIZE); + if (!instance->bulk_scratch) { + err = -ENOMEM; + goto err_free_instance; + } instance->vchiq_instance = vchiq_instance; mutex_init(&instance->context_map_lock); @@ -1940,6 +1944,7 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance) destroy_workqueue(instance->bulk_wq); err_free: vfree(instance->bulk_scratch); +err_free_instance: kfree(instance); err_shutdown_vchiq: vchiq_shutdown(vchiq_instance); --