From 004d05d42a12c8e3f2d3402e7d8e24018edff50b Mon Sep 17 00:00:00 2001 From: Neeraj Upadhyay Date: Tue, 9 Mar 2021 16:52:14 +0530 Subject: [PATCH] soc: qcom: Improve msm_minidump_remove_region api Improve the api to better handle certain error scenarios and move console prints outside of irq/locked code sections. Change-Id: I0ec6f37400949c014ea2e94f61a239294c954bf5 Signed-off-by: Neeraj Upadhyay --- drivers/soc/qcom/msm_minidump.c | 34 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/drivers/soc/qcom/msm_minidump.c b/drivers/soc/qcom/msm_minidump.c index a86f882900b7..ccca4c0d76a2 100644 --- a/drivers/soc/qcom/msm_minidump.c +++ b/drivers/soc/qcom/msm_minidump.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved. */ #define pr_fmt(fmt) "Minidump: " fmt @@ -371,7 +371,7 @@ int msm_minidump_clear_headers(const struct md_region *entry) int msm_minidump_remove_region(const struct md_region *entry) { - int rcount, ecount, seq = 0, rgno, ret; + int rcount, ecount, seq = 0, rgno, entryno, ret; unsigned long flags; if (!entry || !minidump_table.md_ss_toc || @@ -381,30 +381,28 @@ int msm_minidump_remove_region(const struct md_region *entry) spin_lock_irqsave(&mdt_lock, flags); write_lock(&mdt_remove_lock); + entryno = md_entry_num(entry); + rgno = md_region_num(entry->name, &seq); + if (entryno < 0 || rgno < 0) { + write_unlock(&mdt_remove_lock); + spin_unlock_irqrestore(&mdt_lock, flags); + pr_err("Not able to find the entry %s (%d,%d) in table\n", + entry->name, entryno, rgno); + return -EINVAL; + } ecount = minidump_table.num_regions; rcount = minidump_table.md_ss_toc->ss_region_count; - rgno = md_entry_num(entry); - if (rgno < 0) { - pr_err("Not able to find the entry in table\n"); - goto out; - } - - if (first_removed_entry > rgno) - first_removed_entry = rgno; + if (first_removed_entry > entryno) + first_removed_entry = entryno; minidump_table.md_ss_toc->md_ss_toc_init = 0; /* Remove entry from: entry list, ss region list and elf header */ - memmove(&minidump_table.entry[rgno], &minidump_table.entry[rgno + 1], - ((ecount - rgno - 1) * sizeof(struct md_region))); + memmove(&minidump_table.entry[entryno], + &minidump_table.entry[entryno + 1], + ((ecount - entryno - 1) * sizeof(struct md_region))); memset(&minidump_table.entry[ecount - 1], 0, sizeof(struct md_region)); - rgno = md_region_num(entry->name, &seq); - if (rgno < 0) { - pr_err("Not able to find region in table\n"); - goto out; - } - memmove(&minidump_table.md_regions[rgno], &minidump_table.md_regions[rgno + 1], ((rcount - rgno - 1) * sizeof(struct md_ss_region)));