Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7BC29C5AD4C for ; Thu, 23 Nov 2023 18:06:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3ECE510E172; Thu, 23 Nov 2023 18:06:17 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id D5D7510E172 for ; Thu, 23 Nov 2023 18:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700762774; x=1732298774; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Ob6O1659P4hnTQmfAqgFASc7PhP4zLyF3qELbNlKDmI=; b=g1Lv5kLgZXslNw8w5bwwd8Yt+Ms76Y7zUpi3OLkY5fTHKQUXcPy/ny65 HYAPDt6kDhj+jQChQpEqxtTGkcuUMR3lHklB5jhJq+j2VuqvXogrQSv3a sCL/SIKwjsjImiSoIXCT0rG4aLoqubHffoglaBwzWgAmcFFpVs2ThPV/f 7BS4EEvRYlHbHAmCSMd/OFLriHID86TBmoFEtYigvClvTgs+weXO4xt4O KhOUscEyKEZV1emVb41kqkN8Naq5zFI4ceMgPrqTvRSXu1xetaH6ODIGL rLbpNrgyeO7yyvudZ+EmCH4g8w09P5Ze8VL0hN6PVfqxsg+R9bISGDkYP w==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="392081302" X-IronPort-AV: E=Sophos;i="6.04,222,1695711600"; d="scan'208";a="392081302" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 10:06:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="885053743" X-IronPort-AV: E=Sophos;i="6.04,222,1695711600"; d="scan'208";a="885053743" Received: from josouza-mobl2.bz.intel.com ([10.87.243.88]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 10:06:12 -0800 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= To: intel-xe@lists.freedesktop.org Date: Thu, 23 Nov 2023 10:06:04 -0800 Message-ID: <20231123180605.112597-1-jose.souza@intel.com> X-Mailer: git-send-email 2.42.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Intel-xe] [PATCH 1/2] devcoredump: Add dev_coredump_put() X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rodrigo Vivi Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" Add function to remove device coredump, this is useful to release resources allocated by device before unload. Without this coredump would only be removed after DEVCD_TIMEOUT seconds. Cc: Rodrigo Vivi Signed-off-by: José Roberto de Souza --- drivers/base/devcoredump.c | 21 +++++++++++++++++++++ include/linux/devcoredump.h | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c index 91536ee05f144..444bb510b6ef4 100644 --- a/drivers/base/devcoredump.c +++ b/drivers/base/devcoredump.c @@ -304,6 +304,27 @@ static ssize_t devcd_read_from_sgtable(char *buffer, loff_t offset, offset); } +/** + * dev_coredump_put - remove device coredump + * @dev: the struct device for the crashed device + * + * If giving device has a coredump this frees data and remove coredump, + * otherwise does nothing. + * This is useful to release resources allocated by device before unload it. + */ +void dev_coredump_put(struct device *dev) +{ + struct device *existing; + + existing = class_find_device(&devcd_class, NULL, dev, + devcd_match_failing); + if (existing) { + devcd_free(existing, NULL); + put_device(existing); + } +} +EXPORT_SYMBOL_GPL(dev_coredump_put); + /** * dev_coredumpm - create device coredump with read/free methods * @dev: the struct device for the crashed device diff --git a/include/linux/devcoredump.h b/include/linux/devcoredump.h index c008169ed2c6f..c8f7eb6cc1915 100644 --- a/include/linux/devcoredump.h +++ b/include/linux/devcoredump.h @@ -63,6 +63,8 @@ void dev_coredumpm(struct device *dev, struct module *owner, void dev_coredumpsg(struct device *dev, struct scatterlist *table, size_t datalen, gfp_t gfp); + +void dev_coredump_put(struct device *dev); #else static inline void dev_coredumpv(struct device *dev, void *data, size_t datalen, gfp_t gfp) @@ -85,6 +87,9 @@ static inline void dev_coredumpsg(struct device *dev, struct scatterlist *table, { _devcd_free_sgtable(table); } +static inline void dev_coredump_put(struct device *dev) +{ +} #endif /* CONFIG_DEV_COREDUMP */ #endif /* __DEVCOREDUMP_H */ -- 2.42.1