Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1190819pxb; Wed, 6 Apr 2022 10:54:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0LR/oEbEACA3qVU46fQg2zPGLXGnnKZjfREkTPdheKUETmSkIiA2SBL52bxBvux7Ucio6 X-Received: by 2002:a05:6a00:14ca:b0:4fb:5d3e:5f77 with SMTP id w10-20020a056a0014ca00b004fb5d3e5f77mr10203990pfu.34.1649267694668; Wed, 06 Apr 2022 10:54:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649267694; cv=none; d=google.com; s=arc-20160816; b=MEbv0E7wMYC3RWD1zbmvAmDUJ+wN16OYS9rddzi/opMfYdIN/7o6CjalEO2n5GXuR7 V293Rh/NZiyVlIC40LzKJMAVSmtZml1p6yu8RPAoXG9b0L+Cgmsxn71Azo6OKvzoTMVO yUGhMnIDG77evvv3u1Me6mhlsIczoS/FHsVNQMXSExmlnqtvZHXJe+5VLipIXHt8Tjm6 04LJkSWTYeL2Qg700Mr7yMC7bre2nf9XbOZhYyiyhslqc/HEVQSFODIi6SYKm43fLQUr PH0Vhy9XXJ4StCcKpeOUNQo4y/22tcVdUAYLvEI6aPJ2O+dg2RP8VjS12RfPW1P845Js F6xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=J9a2BqBVokvTsgXQbtymYfO3sWscM/hLjb0STJ5+gfo=; b=Ph8lZF6ejWL4ze6xdyB2hjSm8W+xVsuvHZgP4FQkyh5zihu3JPfN3xca0mNVXrHqYN j3ROMyPrMWfLWb6BcpmtYLYZK5+3drvyfLcwjrJZGFIUM2BfUadhJPs4MOauryHPXrRN /QOvMDD7qcXb8Ny/3XyBEqn/SJNhb2tZ6L9FnabeYnPPZtTI/WPUjkQWnQDLchOXYznO CI+7yjQYieYW0QmRtwLuc0V3sdPSrvSGdPGU2UX9DAPWNWq8Tpe4pByoehjGXhcoThGP r+Cy3rkh7cSEsfekIdfWDLGRg6OW8G6Ql9xU750CH27BZY5FTRii/sIquuxFAN0GAf5o 7qaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZLBha3uf; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m6-20020a656a06000000b003825f9c93a9si19693087pgu.524.2022.04.06.10.54.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 10:54:54 -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=@gmail.com header.s=20210112 header.b=ZLBha3uf; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D09D45DA36; Wed, 6 Apr 2022 10:46:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239461AbiDFRsj (ORCPT + 99 others); Wed, 6 Apr 2022 13:48:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239925AbiDFRrz (ORCPT ); Wed, 6 Apr 2022 13:47:55 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A040A10BD22; Wed, 6 Apr 2022 09:23:29 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id k23so4017714wrd.8; Wed, 06 Apr 2022 09:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=J9a2BqBVokvTsgXQbtymYfO3sWscM/hLjb0STJ5+gfo=; b=ZLBha3ufL0jqhFoZzUzSgpHsnHd6DM/HSKIHl7RHPuuFY1C1cWUqC0PfmMqS7DfunJ Dky80ByJLgonPzNihsl2DXLyMlG2HbrxCQsQtCbp92JDX62+0uWXZ/XEN2OUXX5L8okT l+3ZdiwM34ISMZtglwh0Nr/0cU6YMcyjlAOt1fK307cGVY5BMZwtRE/R3iw6kGLLhlYm qSxsiaAwSPmtRYrHmrhSi3H7OUENgEptGKC9vdm2kyX8NrGkbQIIS+4IwvDduTDGpdoQ DigItKzsvp5rE9c8Y9TXEe0Y/CHcbfPrSzNP3deLbKRmbTIW88KJDJJTXX10Ss517V8d iw+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=J9a2BqBVokvTsgXQbtymYfO3sWscM/hLjb0STJ5+gfo=; b=oBf/ACoukip41uS6lNYXOo2BPEWFvaLxYi0r2SAWFWgJtVE9YbQXNzYwPqR5ecavcD QgU146s6OLuZnEvHVrtszRhdsS4XtWICHGGnq9nJ0/ViHaaVflF1eYdXshEpyBieBJyo RIrIFs1AVmNSlvZXdzAjln/Rub23WudyG6WPVHh29dtdBcIMd8fJtlrdCT1zv/WWKXcH mAVHHlAou3G2Ks/vQSyanqvQcHQp1MopJGySOAKziKFchDPFeNea5P4cHuKXFd6RlBN1 I0gaRBOcqk/+q/g4zinXn05YuUzhZfCWg8Ad2v+38lCBTwioYkdnV1Y0JQNcY3K5z9b0 dFRw== X-Gm-Message-State: AOAM533U5SsHMG7mi2ODs8/YJXkkw55LbUjJDAcz7GOsJ/P5nn1F0kT+ Wbo4QlUraTQ5T/kW4+qptw2/M1gC2+xNbukimhpHVi1Y X-Received: by 2002:adf:9111:0:b0:206:c9b:ce0d with SMTP id j17-20020adf9111000000b002060c9bce0dmr7345582wrj.418.1649262207917; Wed, 06 Apr 2022 09:23:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Rob Clark Date: Wed, 6 Apr 2022 09:24:22 -0700 Message-ID: Subject: Re: [PATCH] drm/msm/mdp5: check the return of kzalloc() To: xkernel.wang@foxmail.com Cc: Sean Paul , David Airlie , Daniel Vetter , linux-arm-msm , dri-devel , freedreno , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" 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 On Thu, Mar 24, 2022 at 1:37 AM wrote: > > 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; At this point, you could just: if (!mdp5_state) return; BR, -R > > - 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 * > --