From patchwork Mon Oct 14 16:36:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 835188 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2D2A175B1 for ; Mon, 14 Oct 2024 16:37:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728923856; cv=none; b=XHdeVBMbpolrKhyGvJONb8280qTds2Sa96AZcYzE9evSkdNjF1nLucR6sY7ehhsbGM/Saft6zP8gbvs2sioZMQL0e78LFwt34nxqLymAEb/PZYbpHMbR33mXPcnRVZQ1lXp6tBAQOlmyWnTHKdjVkZqnANIeWLibnUYR09kH3B4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728923856; c=relaxed/simple; bh=bTtG4MB3yjrdSPMsQ2e3jywBt+U40h9Vr1j3XOPrBNE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=UXQmhIU+2gFwESxgOkgXbS1hrL37peKEUAFvazjFzdX8HsIgS8qZx3FOMDb/M2c5kOkVilQXO+bikMX+Wohjb96RGfcDr3TjICKQC7YxJgWRGp9HdaTsrPaRwKfZZ/SfDrwLIqJiN54hz8tZ15Rmd97vR7BNqZZySKMO/+zcW/M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=cVhrqnpb; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="cVhrqnpb" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71e6f1a5a19so470792b3a.3 for ; Mon, 14 Oct 2024 09:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1728923854; x=1729528654; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Eq6RmtQgXylpaIuQSD/eFivfyV/YbUHAedXEkzzSSXc=; b=cVhrqnpbKclAuARyWtF73cvf6JxI6cb5Oal04gv5+1y3HofmxXUZ66xOdXJFwoaaL2 LurlygUEHq922C31Mw36x8UxXZShejvxwOFvD8F3MxMcrQTRhyaAcZYPHaZKsbtZ3DSc W/hsR8r/ElkhXQvAYnLSEE/MuPpaGpjarGESc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728923854; x=1729528654; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Eq6RmtQgXylpaIuQSD/eFivfyV/YbUHAedXEkzzSSXc=; b=bJG0if06zL4PF0Vq158yMQq6KbnNvbDEeq0zip5dhUjN2Y3bsCjd6PiUaUwCvdNBmO qf4lLRvoGqssRo1GM5CaUTFZuHBtQzLXBkWx2K8kooe8EI7ufX64o6CoSaSEnHzTs7GN 9xDm6PTMQqZ4EHSzXty55qz0wykkbm/BNxCePTiYHnJp4LO7mCmAxSIKDQpxujhwYEyQ NvViWhFggbSOIjAkzGIrlDzJ3Qi+2369eriE4gc+mpKwQtTQk41+ndfBHyGbFjAt/67x Ra/rTOrH9Pb8L+DGbgJj39cZmuk/YOaoF1UHsPkKRMhtKNfAmbNZEc2/m5ZqKTTvGxEG BdYA== X-Forwarded-Encrypted: i=1; AJvYcCVoCvWOuKpYmiqICxiy3/dsV1k8itvq1M7/n2yPz55ixMfnkU7/mY7Ruwkriwn3cByK0TMUYs8w0mqklsRt@vger.kernel.org X-Gm-Message-State: AOJu0YzbozjJFRutddM7FoGNZ03pr4LQ+u/JHukT2rTsB+/vtQwOXgr6 K8rtyaHjNGc31NeDaXU7Y+psJpXKPeYiGBLxCpRGxHVhTCyWH1J1gtvV3LsH2A== X-Google-Smtp-Source: AGHT+IFrI6AyFlAD+rPt6sq8RJjzjcPvxnHIHU5bh4fmZllt0MuEFWzqp3sZJTWGMBx/myacl4Lxew== X-Received: by 2002:a05:6a00:9282:b0:717:9154:b5d6 with SMTP id d2e1a72fcca58-71e37f4ed89mr19746704b3a.22.1728923853741; Mon, 14 Oct 2024 09:37:33 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:1e71:8a09:a3b:1e00]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e51dc0617sm4383693b3a.165.2024.10.14.09.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 09:37:32 -0700 (PDT) From: Douglas Anderson To: Rob Clark , Abhinav Kumar , Dmitry Baryshkov Cc: Stephen Boyd , Douglas Anderson , David Airlie , Marijn Suijten , Sean Paul , Simona Vetter , dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] drm/msm: Avoid NULL dereference in msm_disp_state_print_regs() Date: Mon, 14 Oct 2024 09:36:08 -0700 Message-ID: <20241014093605.1.Ia1217cecec9ef09eb3c6d125360cc6c8574b0e73@changeid> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If the allocation in msm_disp_state_dump_regs() failed then `block->state` can be NULL. The msm_disp_state_print_regs() function _does_ have code to try to handle it with: if (*reg) dump_addr = *reg; ...but since "dump_addr" is initialized to NULL the above is actually a noop. The code then goes on to dereference `dump_addr`. Make the function print "Registers not stored" when it sees a NULL to solve this. Since we're touching the code, fix msm_disp_state_print_regs() not to pointlessly take a double-pointer and properly mark the pointer as `const`. Fixes: 98659487b845 ("drm/msm: add support to take dpu snapshot") Signed-off-by: Douglas Anderson Reviewed-by: Abhinav Kumar --- drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c b/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c index add72bbc28b1..bb149281d31f 100644 --- a/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c +++ b/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c @@ -48,20 +48,21 @@ static void msm_disp_state_dump_regs(u32 **reg, u32 aligned_len, void __iomem *b } } -static void msm_disp_state_print_regs(u32 **reg, u32 len, void __iomem *base_addr, - struct drm_printer *p) +static void msm_disp_state_print_regs(const u32 *dump_addr, u32 len, + void __iomem *base_addr, struct drm_printer *p) { int i; - u32 *dump_addr = NULL; void __iomem *addr; u32 num_rows; + if (!dump_addr) { + drm_printf(p, "Registers not stored\n"); + return; + } + addr = base_addr; num_rows = len / REG_DUMP_ALIGN; - if (*reg) - dump_addr = *reg; - for (i = 0; i < num_rows; i++) { drm_printf(p, "0x%lx : %08x %08x %08x %08x\n", (unsigned long)(addr - base_addr), @@ -89,7 +90,7 @@ void msm_disp_state_print(struct msm_disp_state *state, struct drm_printer *p) list_for_each_entry_safe(block, tmp, &state->blocks, node) { drm_printf(p, "====================%s================\n", block->name); - msm_disp_state_print_regs(&block->state, block->size, block->base_addr, p); + msm_disp_state_print_regs(block->state, block->size, block->base_addr, p); } drm_printf(p, "===================dpu drm state================\n"); From patchwork Mon Oct 14 16:36:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 836274 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B3C71B4F2B for ; Mon, 14 Oct 2024 16:37:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728923857; cv=none; b=euaHLHcWkiWTweSMFi2AoKqL8zKvNjuUL3yzGiZ7aMV5KRcN3fwHU1VgE3Uz8ChJwT+0E78B8V2w2S/siOQr7Y6nvz+AyYtAcUDqshk3vkjoTgwlOsMFK84W0B9Il2dfNg4EBipgXb1TPOHhG9ESUYutJR9+nOXrqKIo6wTORVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728923857; c=relaxed/simple; bh=2/hmtua87SYdIDexDgVCKHz9vUkiTbZvg8psKON5ws8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U4CRQRAfXTO94c8hlQk4J6zb1j8ve0ZJWzJaZR47jAAd//+76SQaHhzFAXgEcT7ql2YtLys1sMXSIkUw3fpbEitRXSFbritefCp7shWFpfdopgdrEIJXmLjgEPvB6oGjjL4bsNZU3JjWxD+4Q9G7EZqp/GZy8zkQNZgeG1ykG0U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=F38Muk8+; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="F38Muk8+" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-7e6ed072cdaso2813751a12.0 for ; Mon, 14 Oct 2024 09:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1728923856; x=1729528656; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y0QDCUs/8D4jixu/KfGYmNxOa4c0mSZ3kXKt5t3/Xv8=; b=F38Muk8+ubO/O1hHJJUXOviHhlmfLWadzyoLHpbrlQr0n7+4u+qlkKa2PH7XxStqYm QM5P+hPgiwRVMKvOz1w7rDzj5ouWe90/xHTzS8ipJIhWEVRhdjuf1SKG6EXJlUc3q1pt OpL7MgrHofzaIVt5M36A3ou+ab51zyx8FHHBI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728923856; x=1729528656; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y0QDCUs/8D4jixu/KfGYmNxOa4c0mSZ3kXKt5t3/Xv8=; b=SkYVicYjBAMEV1Yz5twf2MgiLYqKDofzMAkBQcQG7VwODD3Zn0HWq3ohWhZ+O5W5Gb uePUZmhGZdJGIdlgAz63UVqF3Beh/M/T/gvuV+W390hsPb3e/YT/DPp7+KiM9In9Q0bp cXvhKE2VwJi7dIk8y31oSuVVZbDMs0GTytSYfecoPdGWtPVRCP/FRftgl4qrEKT91gs4 tBro9j/a06yagFQWtRzkM+xxHtykAP4AXbL9QdEbvOz0cC6sAvLQe3KrhgxMHNgLo5K+ X/UjTcvAU9J4zidLNAM+nG6LtdKCzdMRYFO0EZs/0kHPfY2FZ73kOjxmxtkbrH6FS8x0 dySg== X-Forwarded-Encrypted: i=1; AJvYcCWP3QE53fvyhhEHeR86KjknqxREXSZW5HojhxiTfx7FyW3ja/uAH//OjLOAi+w4ydnBhE7l3FqytajgS+wJ@vger.kernel.org X-Gm-Message-State: AOJu0Yy/Kq2nBeQaP+4rfnGJvC1AvBDvWkJE0Dm4bbK+3tzt4xqzQd8X hW1P1J1Ye5qcOq0DjtAmVqQnsoq7xtJ89kAHD2VHaiCxMBL+a7ssAf4TKm9jRQ== X-Google-Smtp-Source: AGHT+IGux4tneH6GmBs7wM4quuJ0YGWj3+34YGtAX6dD/SdcV19l8y70Ofmfq5jY72pPsYNjcr0LjA== X-Received: by 2002:a05:6a21:168d:b0:1d8:bbc9:37c7 with SMTP id adf61e73a8af0-1d8c969074dmr13073659637.36.1728923855948; Mon, 14 Oct 2024 09:37:35 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:1e71:8a09:a3b:1e00]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e51dc0617sm4383693b3a.165.2024.10.14.09.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 09:37:35 -0700 (PDT) From: Douglas Anderson To: Rob Clark , Abhinav Kumar , Dmitry Baryshkov Cc: Stephen Boyd , Douglas Anderson , David Airlie , Marijn Suijten , Sean Paul , Simona Vetter , dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] drm/msm: Allocate memory for disp snapshot with kvzalloc() Date: Mon, 14 Oct 2024 09:36:09 -0700 Message-ID: <20241014093605.2.I72441365ffe91f3dceb17db0a8ec976af8139590@changeid> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241014093605.1.Ia1217cecec9ef09eb3c6d125360cc6c8574b0e73@changeid> References: <20241014093605.1.Ia1217cecec9ef09eb3c6d125360cc6c8574b0e73@changeid> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With the "drm/msm: add a display mmu fault handler" series [1] we saw issues in the field where memory allocation was failing when allocating space for registers in msm_disp_state_dump_regs(). Specifically we were seeing an order 5 allocation fail. It's not surprising that order 5 allocations will sometimes fail after the system has been up and running for a while. There's no need here for contiguous memory. Change the allocation to kvzalloc() which should make it much less likely to fail. [1] https://lore.kernel.org/r/20240628214848.4075651-1-quic_abhinavk@quicinc.com/ Fixes: 98659487b845 ("drm/msm: add support to take dpu snapshot") Signed-off-by: Douglas Anderson --- drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c b/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c index bb149281d31f..4d55e3cf570f 100644 --- a/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c +++ b/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c @@ -26,7 +26,7 @@ static void msm_disp_state_dump_regs(u32 **reg, u32 aligned_len, void __iomem *b end_addr = base_addr + aligned_len; if (!(*reg)) - *reg = kzalloc(len_padded, GFP_KERNEL); + *reg = kvzalloc(len_padded, GFP_KERNEL); if (*reg) dump_addr = *reg; @@ -162,7 +162,7 @@ void msm_disp_state_free(void *data) list_for_each_entry_safe(block, tmp, &disp_state->blocks, node) { list_del(&block->node); - kfree(block->state); + kvfree(block->state); kfree(block); } From patchwork Mon Oct 14 16:36:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 835187 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3D9A1BF7E8 for ; Mon, 14 Oct 2024 16:37:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728923860; cv=none; b=jQ8SbVmt/z0b4m0WG/aNOVdM/QD3KPWMyzN31e79jQLRLSTe4LXkKVbT6escxs7W6dOWxbzg4tQan47xi0n0cjEru3MV9nmGXDljcVoPoHxeSdepZIgCOmR9pK0u9yimOCRRQhiuFFnkWpC0mrhol+U+x90rmFLdmmsjuS2yyvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728923860; c=relaxed/simple; bh=idzxZir+2Hfx66wZzXdoO5vCmyD32OzgN5agHfHyqSA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MgZ8LfYqBHFhXWBMkMI04V1l4KtSjIJSGFOW5Vj3+R/4+9V+1HX83Nwl0bYVTpSObHdOOBVXdVQ7iGUOPcQuHf+griuYyiLvqPJkNo8TmFPsilFuR5qrHsH7NvKawRowwkK3ZM94alPTEC6+fkOCXll0Ln+e1wD2ZPvs0TSBWCo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=gO+wrm3+; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="gO+wrm3+" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-71e70c32cd7so395003b3a.1 for ; Mon, 14 Oct 2024 09:37:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1728923858; x=1729528658; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sVGl2ftbuqqnUqeIL1a1bElRQ/ry6hMTlQBnPSxP8Dk=; b=gO+wrm3+Vydx8j/CFtfxG7Qi+6tq+Mei4x2pFlSHkhmj/65i4na9W05dsV3hUkbrYi JMJzvDDlz19HqzALzl9Ou1AowCbsCT3BacsQxNg/yP7/HMb1uI1/3NJd5YHbomxA6GSY UbC75cb+BVP9Jam14rHp5B3I+2armcGj1NmaE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728923858; x=1729528658; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sVGl2ftbuqqnUqeIL1a1bElRQ/ry6hMTlQBnPSxP8Dk=; b=Nww8i7eCHvLr9EHmHazJcLzAIZI7rmBcUZkup4VqPwA2JK496xr5kut9UeZn+pj944 ydMGGeJo4mdA6supHebhtt6JRLt45j/GKJFDPG4GY+ZJOWXsEFIUDCF29YbjFmt9DBOO OKJF5aRRZ5aZbz0ChF3Ok/+gj8t9TzJkLCEzqsEpVpWEjlXrEukMyBM30HCriTUX89PA o9a5ZgfcWCxTRTGfA6rNstw5oKV7yvmmctBmYp+onWtp9gf+gvPWBOBL4NFnVSBheQdP 0Rz9OzqPqhiT+9XL6iDLdYc9dsUKt7JgIeMD55DndDUwMKU9XOyfH/28XHWIGmgR//bF WLMQ== X-Forwarded-Encrypted: i=1; AJvYcCUvts7VfZ54v7PkWuDJza9HhNvaxwqSEyKw89T4lwqDdlpO9QgJr3sgNClzGVD30TqBsiaXBJ0+23E3cc99@vger.kernel.org X-Gm-Message-State: AOJu0Yy9yCNxII3cPFXEe16cQhpTlOLgjWgblsCbep3YgiUnkOHwLBiP cwwVYtuOzJdSguvBrIIQdqVQoPGiqX9N7JPZNPX+zCQKL4qeMsyTnX5Tzq4eKg== X-Google-Smtp-Source: AGHT+IEguS+DYgfr50X3amlVgerOKKT45qvqYFP4etgOkkRvUpQ1dDg9fKu0+t5LQwDSWp3K3ICKxw== X-Received: by 2002:a05:6a00:4652:b0:71e:4c86:659a with SMTP id d2e1a72fcca58-71e4c866d72mr13703071b3a.9.1728923858137; Mon, 14 Oct 2024 09:37:38 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:1e71:8a09:a3b:1e00]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e51dc0617sm4383693b3a.165.2024.10.14.09.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 09:37:37 -0700 (PDT) From: Douglas Anderson To: Rob Clark , Abhinav Kumar , Dmitry Baryshkov Cc: Stephen Boyd , Douglas Anderson , David Airlie , Marijn Suijten , Sean Paul , Simona Vetter , dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] drm/msm: Simplify NULL checking in msm_disp_state_dump_regs() Date: Mon, 14 Oct 2024 09:36:10 -0700 Message-ID: <20241014093605.3.I66049c2c17bd82767661f0ecd741b20453da02b2@changeid> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241014093605.1.Ia1217cecec9ef09eb3c6d125360cc6c8574b0e73@changeid> References: <20241014093605.1.Ia1217cecec9ef09eb3c6d125360cc6c8574b0e73@changeid> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The msm_disp_state_dump_regs(): - Doesn't allocate if the caller already allocated. ...but there's one caller and it doesn't allocate so we don't need this check. - Checks for allocation failure over and over even though it could just do it once right after the allocation. Clean this up. Signed-off-by: Douglas Anderson --- .../gpu/drm/msm/disp/msm_disp_snapshot_util.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c b/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c index 4d55e3cf570f..07a2c1e87219 100644 --- a/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c +++ b/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c @@ -25,24 +25,21 @@ static void msm_disp_state_dump_regs(u32 **reg, u32 aligned_len, void __iomem *b addr = base_addr; end_addr = base_addr + aligned_len; - if (!(*reg)) - *reg = kvzalloc(len_padded, GFP_KERNEL); - - if (*reg) - dump_addr = *reg; + *reg = kvzalloc(len_padded, GFP_KERNEL); + if (!*reg) + return; + dump_addr = *reg; for (i = 0; i < num_rows; i++) { x0 = (addr < end_addr) ? readl_relaxed(addr + 0x0) : 0; x4 = (addr + 0x4 < end_addr) ? readl_relaxed(addr + 0x4) : 0; x8 = (addr + 0x8 < end_addr) ? readl_relaxed(addr + 0x8) : 0; xc = (addr + 0xc < end_addr) ? readl_relaxed(addr + 0xc) : 0; - if (dump_addr) { - dump_addr[i * 4] = x0; - dump_addr[i * 4 + 1] = x4; - dump_addr[i * 4 + 2] = x8; - dump_addr[i * 4 + 3] = xc; - } + dump_addr[i * 4] = x0; + dump_addr[i * 4 + 1] = x4; + dump_addr[i * 4 + 2] = x8; + dump_addr[i * 4 + 3] = xc; addr += REG_DUMP_ALIGN; }