Skip to content

Commit a28380f

Browse files
zehortigozarodrigovivi
authored andcommitted
devcoredump: Add dev_coredump_put()
It is useful for modules that do not want to keep coredump available after its unload. Otherwise, the coredump would only be removed after DEVCD_TIMEOUT seconds. v2: - dev_coredump_put() documentation updated (Mukesh) Cc: Rodrigo Vivi <rodrigo.vivi@intel.com> Cc: Mukesh Ojha <quic_mojha@quicinc.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Jonathan Cavitt <jonathan.cavitt@intel.com> Reviewed-by: Johannes Berg <johannes@sipsolutions.net> Acked-by: Jonathan Cavitt <jonathan.cavitt@intel.com> Signed-off-by: José Roberto de Souza <jose.souza@intel.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://patchwork.freedesktop.org/patch/msgid/20240409200206.108452-1-jose.souza@intel.com Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
1 parent ac321eb commit a28380f

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

drivers/base/devcoredump.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,29 @@ static ssize_t devcd_read_from_sgtable(char *buffer, loff_t offset,
304304
offset);
305305
}
306306

307+
/**
308+
* dev_coredump_put - remove device coredump
309+
* @dev: the struct device for the crashed device
310+
*
311+
* dev_coredump_put() removes coredump, if exists, for a given device from
312+
* the file system and free its associated data otherwise, does nothing.
313+
*
314+
* It is useful for modules that do not want to keep coredump
315+
* available after its unload.
316+
*/
317+
void dev_coredump_put(struct device *dev)
318+
{
319+
struct device *existing;
320+
321+
existing = class_find_device(&devcd_class, NULL, dev,
322+
devcd_match_failing);
323+
if (existing) {
324+
devcd_free(existing, NULL);
325+
put_device(existing);
326+
}
327+
}
328+
EXPORT_SYMBOL_GPL(dev_coredump_put);
329+
307330
/**
308331
* dev_coredumpm - create device coredump with read/free methods
309332
* @dev: the struct device for the crashed device

include/linux/devcoredump.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ void dev_coredumpm(struct device *dev, struct module *owner,
6363

6464
void dev_coredumpsg(struct device *dev, struct scatterlist *table,
6565
size_t datalen, gfp_t gfp);
66+
67+
void dev_coredump_put(struct device *dev);
6668
#else
6769
static inline void dev_coredumpv(struct device *dev, void *data,
6870
size_t datalen, gfp_t gfp)
@@ -85,6 +87,9 @@ static inline void dev_coredumpsg(struct device *dev, struct scatterlist *table,
8587
{
8688
_devcd_free_sgtable(table);
8789
}
90+
static inline void dev_coredump_put(struct device *dev)
91+
{
92+
}
8893
#endif /* CONFIG_DEV_COREDUMP */
8994

9095
#endif /* __DEVCOREDUMP_H */

0 commit comments

Comments
 (0)