Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1274047pxb; Thu, 24 Mar 2022 16:38:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxA3TMzc5a21UnFnyocZvYp1FLX3FGhcBO/jUeBrWc2l1R/1udua/869/VF5edo67CyvCHG X-Received: by 2002:a17:90b:1e04:b0:1c6:fbac:b0e2 with SMTP id pg4-20020a17090b1e0400b001c6fbacb0e2mr21255626pjb.207.1648165113102; Thu, 24 Mar 2022 16:38:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648165113; cv=none; d=google.com; s=arc-20160816; b=e3y5pVz3TFv3ZTXf3D13HOc5ED0c5F2wTZ/if3+TZolbCcGcVzXYOXDW04d/Y3nDSY PedcS5/JuVRQJ3Dtbwkm+8gFQuo+bYrruN9koDt8reY6ZZ9X8pxUzEBnaY3MNMPx+3qC yDdkXgA/hmilOdbA7aI7iL7wd/aWenz3SbaVoTSnnqLQadz9B/Q1eHeX2EAbj6yQvRJg wOdp9V0Y0faI9wpMEiTJbI6FS7Yp0mhPZZptbmJW/sAz6MrxbOYbcOfRn4IVDoLasqlh 0a3L/mLbx5e78uC2UUL3DjQZr2BeNezIMQfrqv0dLCpkzeno6gcYUg1X2tO7ZBLpEnkg G7nQ== 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=PdI9M8lLoPowcX452EcX6k9LkvHzZyFe5xCg2aOT5z4=; b=NZmqq04X6lDwBYI5KLpDo/kb8sy0g9I8Egh0VBW9wAamoZ8L6l6rQotw6forNQBRwF yHZzSrO2OuF2IssQW3WJHXzhf5Ufy7LIbq2Ui+vyjbwPuuAKnRRLUvnL9u17Wb53Pvhs nYKeQurRprJPs/k8IEzpXhZGB6EQ1dpBsMB+TxinY9vrLUxa8nhaabmjjVMIrlPjfH4W vdHGxd1IDLMyjlNPj5j+GZ6ZQGJRQL3plLuF3VAzrPy7TfYU+wEds7D2F3uKU0TKdIrs IX+IFQIASc8ONhZddUKQ8zs7rUQYGyGHELxhl++fyvSpLbOS59evPQJCfMnZACcDdW7H 8kYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=uAm3f1Pp; 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=foxmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cj14-20020a056a00298e00b004fa3a8dffc8si919608pfb.127.2022.03.24.16.38.18; Thu, 24 Mar 2022 16:38:33 -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=@foxmail.com header.s=s201512 header.b=uAm3f1Pp; 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=foxmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348966AbiCXIii (ORCPT + 99 others); Thu, 24 Mar 2022 04:38:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238643AbiCXIih (ORCPT ); Thu, 24 Mar 2022 04:38:37 -0400 Received: from out203-205-251-84.mail.qq.com (unknown [203.205.251.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47D689BBA4 for ; Thu, 24 Mar 2022 01:37:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1648111021; bh=PdI9M8lLoPowcX452EcX6k9LkvHzZyFe5xCg2aOT5z4=; h=From:To:Cc:Subject:Date; b=uAm3f1PpNwAXNIu1B3NhmmPeEKikVrfse3dGm7mM9ns70KSv9hXo1upo6Djw6makO nKiHvtSr3lJErg2uoD8xZKBg8ONEcsLAOAEsap3FjQPU63FhEf6UexzQCIZdqIyOVn wGCXVSqwGIBgUF8ZhXXKY4cs3DuM/T/YR3Yg9UTI= Received: from localhost.localdomain ([218.197.153.188]) by newxmesmtplogicsvrszc6.qq.com (NewEsmtp) with SMTP id 9378DC37; Thu, 24 Mar 2022 16:36:55 +0800 X-QQ-mid: xmsmtpt1648111015tha0g0i7j Message-ID: X-QQ-XMAILINFO: MR/iVh5QLeieiszZ2O+QJKzXzwRb+Wv/lEVxDjwkYxMewJHYJdFQoHsoWu9iam ajhSQ1Eh+e59SwWAJQNIolA9hH/lQO4f1IuiJrqh01QGQQ8ynx0vMZGFAxTrWV/nL4TZ50nEHhCA PfT6P9/3oSVTf0oUQNZhJhUqNJubqPtVBrsJxit3KUIEdtGymqR2GqkLJrTUzGoAP64J8TY8yV9p 9T0ViPj0BviZ2jvNNEeO4NHAnnxVRGooB5Smg4EQfAXjHZ+U7NXD9DeDsulbB2O3WsjEMUwmbUX/ ADBjSHLTH7MBY41RUYPX9dQAZ2Nf+IQGfr4sqwcHe+VpytsaAIb0l8FZdedLnu7owihH7/bB0v9w v3e1RXil9eAuCmyr3rNX5QpjaiLmjhYRpbRUNFtpKlT2xwQQxsCDC/myDcvfbciwVlDxBk0aXiIQ 6QghgDCatQm7ZwMb0INN9vCio1kfph/qKCCfq+BUMpXVtNXVwrPK680hWRBfVJCqkw7acP3mMia3 Bz+5wCSRUSHuDffpafV3/gPepA0ROFJef9Gsx7s+nxaKpeyIQFRfV0LFUVVYToudcy+3otN+loGR TV2OGBWjWfMWM+f8XV5kH6wAGlVxKwqe1uFxN+gqf1S6P+yl890qVRqvI7FjqqQVN/fbXiMgnYpA dL+SUIo8JEJqMcDJYmMpiSylhXfa94+qdeFiHGHkpsTgSA1PD9TvU5C9e+4MnNBOolUOFy1IgNT6 qToKziTVG5vtvfM+IMUbXgPDclAYlMtEC9omhpL+vIOMcjZpQnTE2X8QzS/JTU4yt4gJSPLOaaIG zfCgezFDJ2hrNk3bmb9cBHRKhm+JXn48gMqMCAUX9W7Ns4xzoJFz+KnndZsd0gAL886EkEk6H95v L5nGvh0HYjfeqSczSXqrYSc2ynJYrR+aWjFCZIHMGI4x4PVR9+kQHOwcZuktExV5xkpTnsxCMYqi hfz6C6jwuNs/O3Y468qg== From: xkernel.wang@foxmail.com To: robdclark@gmail.com, sean@poorly.run, airlied@linux.ie, daniel@ffwll.ch Cc: linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org, Xiaoke Wang Subject: [PATCH] drm/msm/mdp5: check the return of kzalloc() Date: Thu, 24 Mar 2022 16:36:44 +0800 X-OQ-MSGID: <20220324083644.2666-1-xkernel.wang@foxmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HELO_DYNAMIC_IPADDR,RDNS_DYNAMIC,SPF_HELO_NONE,SPF_PASS, 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 kzalloc() is a memory allocation function which can return NULL when some internal memory errors happen. So it is better to check it to prevent potential wrong memory access. Signed-off-by: Xiaoke Wang --- drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c index c6b69af..5f914cc 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c @@ -90,15 +90,18 @@ static void mdp5_plane_reset(struct drm_plane *plane) __drm_atomic_helper_plane_destroy_state(plane->state); kfree(to_mdp5_plane_state(plane->state)); - mdp5_state = kzalloc(sizeof(*mdp5_state), GFP_KERNEL); + plane->state = NULL; - if (plane->type == DRM_PLANE_TYPE_PRIMARY) - mdp5_state->base.zpos = STAGE_BASE; - else - mdp5_state->base.zpos = STAGE0 + drm_plane_index(plane); - mdp5_state->base.normalized_zpos = mdp5_state->base.zpos; + mdp5_state = kzalloc(sizeof(*mdp5_state), GFP_KERNEL); + if (mdp5_state) { + if (plane->type == DRM_PLANE_TYPE_PRIMARY) + mdp5_state->base.zpos = STAGE_BASE; + else + mdp5_state->base.zpos = STAGE0 + drm_plane_index(plane); + mdp5_state->base.normalized_zpos = mdp5_state->base.zpos; - __drm_atomic_helper_plane_reset(plane, &mdp5_state->base); + __drm_atomic_helper_plane_reset(plane, &mdp5_state->base); + } } static struct drm_plane_state * --