From patchwork Wed Dec 21 23:19:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marijn Suijten X-Patchwork-Id: 35563 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp33097wrn; Wed, 21 Dec 2022 15:21:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXvikKZWRs0spVLmXSzTcKWC2Cmdq9SBaQfXyGuc+ULIe8c7w12N7GVPV8krSE1UvmV6D5WA X-Received: by 2002:a17:90a:af85:b0:223:f385:bb72 with SMTP id w5-20020a17090aaf8500b00223f385bb72mr3773109pjq.49.1671664884171; Wed, 21 Dec 2022 15:21:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671664884; cv=none; d=google.com; s=arc-20160816; b=YJ2c0FDYYOCtek9PJNANOFCklR8MFFMOy8+zqlWX3HUk8NrP3BEQ3ojsc8kR8BSOQR IH7bxIZMqzJiSdXJ+tYdBxPqzwbZbOApg8Ju8rQruBI6Jnk/NrO18PvVi6A3ju1zatCB 9Cn+0XY62ZtLa12/QXwJ+D8jMQXLhgk+5UFiLW6MWHWqb7We0cHdKIH8yIkoP3pwCxhd gzw7gOfoeukVLdg67q/R2aohI8rZTx3/oQSud49MJ4x8G+OPyZOfkWb+niZyI2CXaoY/ vxO7XbHVHotyaVETxIiSksXkkW0xH3M1KKiEJZpCgh/I2+mgIXvvEgccs75xRkDQzt9x kwqw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0cmCp9RNGU8Fh4k8dTCRzSOlhqWUEp+hXBr/T2dc0rY=; b=jfhwgd1Mdi4RGu7evrT+sceeEnpZ4DMDDMMemuL39gs5h2/sl1kfglGX+R7qYR8sCw dssvWNOIEThBrbf0ELCWjUEWNtRnJSvfscJk9nAbpnWlj4fEZL7gD81BGmDfdovyxymp Dn0PGuoxPiC5ualUuDRS3rOX0zlqYAejFvEHRMhZgMkLfWgCnytn0sMf/4jVJJvp6HlD j4mRlQEcB9vL2yOyvkZPqGabL8z5wfMnwhYQiHE3WN48LAH1gS0VsDR4OQ+6Ad2YyGRT 2bmcnOTmXJ/TvLCWiht76WozZBTr8IqU0aTcGSllqaMLQ+0/cVBYgukFkjDVoOXv0YOx L6Gw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id na17-20020a17090b4c1100b001fd8713170csi3209954pjb.179.2022.12.21.15.20.58; Wed, 21 Dec 2022 15:21:24 -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 S235092AbiLUXUS (ORCPT + 99 others); Wed, 21 Dec 2022 18:20:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234949AbiLUXUF (ORCPT ); Wed, 21 Dec 2022 18:20:05 -0500 Received: from relay02.th.seeweb.it (relay02.th.seeweb.it [IPv6:2001:4b7a:2000:18::163]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8CD724F15 for ; Wed, 21 Dec 2022 15:20:03 -0800 (PST) Received: from localhost.localdomain (94-209-172-39.cable.dynamic.v4.ziggo.nl [94.209.172.39]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by m-r1.th.seeweb.it (Postfix) with ESMTPSA id 74115203C9; Thu, 22 Dec 2022 00:20:01 +0100 (CET) From: Marijn Suijten To: phone-devel@vger.kernel.org, Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Vinod Koul Cc: ~postmarketos/upstreaming@lists.sr.ht, AngeloGioacchino Del Regno , Konrad Dybcio , Martin Botka , Jami Kettunen , Marijn Suijten , Sean Paul , David Airlie , Daniel Vetter , Stephen Boyd , Bjorn Andersson , Jessica Zhang , =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , Kuogee Hsieh , Jani Nikula , sunliming , Sam Ravnborg , Haowen Bai , Konrad Dybcio , Loic Poulain , Vinod Polimera , Douglas Anderson , Vladimir Lypak , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org, Drew Davenport Subject: [PATCH v2 4/8] drm/msm/dpu: Disallow unallocated resources to be returned Date: Thu, 22 Dec 2022 00:19:39 +0100 Message-Id: <20221221231943.1961117-5-marijn.suijten@somainline.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221221231943.1961117-1-marijn.suijten@somainline.org> References: <20221221231943.1961117-1-marijn.suijten@somainline.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752867677519345956?= X-GMAIL-MSGID: =?utf-8?q?1752867677519345956?= In the event that the topology requests resources that have not been created by the system (because they are typically not represented in dpu_mdss_cfg ^1), the resource(s) in global_state (in this case DSC blocks) remain NULL but will still be returned out of dpu_rm_get_assigned_resources, where the caller expects to get an array containing num_blks valid pointers (but instead gets these NULLs). To prevent this from happening, where null-pointer dereferences typically result in a hard-to-debug platform lockup, num_blks shouldn't increase past NULL blocks and will print an error and break instead. After all, max_blks represents the static size of the maximum number of blocks whereas the actual amount varies per platform. ^1: which can happen after a git rebase ended up moving additions to _dpu_cfg to a different struct which has the same patch context. Fixes: bb00a452d6f7 ("drm/msm/dpu: Refactor resource manager") Signed-off-by: Marijn Suijten --- drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c index 73b3442e7467..8471d04bff50 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c @@ -660,6 +660,11 @@ int dpu_rm_get_assigned_resources(struct dpu_rm *rm, blks_size, enc_id); break; } + if (!hw_blks[i]) { + DPU_ERROR("No more resource %d available to assign to enc %d\n", + type, enc_id); + break; + } blks[num_blks++] = hw_blks[i]; }