Signed-off-by: Andrew Morton --- arch/x86/kernel/traps_32.c | 1 + arch/x86/kernel/traps_64.c | 1 + fs/sysfs/file.c | 13 +++++++++++++ fs/sysfs/mount.c | 2 +- fs/sysfs/sysfs.h | 1 + include/linux/sysfs.h | 5 +++++ 6 files changed, 22 insertions(+), 1 deletion(-) diff -puN arch/x86/kernel/traps_32.c~gregkh-driver-sysfs-crash-debugging arch/x86/kernel/traps_32.c --- a/arch/x86/kernel/traps_32.c~gregkh-driver-sysfs-crash-debugging +++ a/arch/x86/kernel/traps_32.c @@ -403,6 +403,7 @@ int __kprobes __die(const char *str, str #endif printk("\n"); + sysfs_printk_last_file(); if (notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV) != NOTIFY_STOP) { diff -puN arch/x86/kernel/traps_64.c~gregkh-driver-sysfs-crash-debugging arch/x86/kernel/traps_64.c --- a/arch/x86/kernel/traps_64.c~gregkh-driver-sysfs-crash-debugging +++ a/arch/x86/kernel/traps_64.c @@ -573,6 +573,7 @@ int __kprobes __die(const char * str, st printk("DEBUG_PAGEALLOC"); #endif printk("\n"); + sysfs_printk_last_file(); if (notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV) == NOTIFY_STOP) return 1; show_registers(regs); diff -puN fs/sysfs/file.c~gregkh-driver-sysfs-crash-debugging fs/sysfs/file.c --- a/fs/sysfs/file.c~gregkh-driver-sysfs-crash-debugging +++ a/fs/sysfs/file.c @@ -16,10 +16,18 @@ #include #include #include +#include #include #include "sysfs.h" +/* used in crash dumps to help with debugging */ +static char last_sysfs_file[PATH_MAX]; +void sysfs_printk_last_file(void) +{ + printk(KERN_EMERG "last sysfs file: %s\n", last_sysfs_file); +} + /* * There's one sysfs_buffer for each open file and one * sysfs_open_dirent for each sysfs_dirent with one or more open @@ -320,6 +328,11 @@ static int sysfs_open_file(struct inode struct sysfs_buffer *buffer; struct sysfs_ops *ops; int error = -EACCES; + char *p; + + p = d_path(&file->f_path, last_sysfs_file, sizeof(last_sysfs_file)); + if (p) + memmove(last_sysfs_file, p, strlen(p) + 1); /* need attr_sd for attr and ops, its parent for kobj */ if (!sysfs_get_active_two(attr_sd)) diff -puN fs/sysfs/mount.c~gregkh-driver-sysfs-crash-debugging fs/sysfs/mount.c --- a/fs/sysfs/mount.c~gregkh-driver-sysfs-crash-debugging +++ a/fs/sysfs/mount.c @@ -22,7 +22,7 @@ /* Random magic number */ #define SYSFS_MAGIC 0x62656572 -static struct vfsmount *sysfs_mount; +struct vfsmount *sysfs_mount; struct super_block * sysfs_sb = NULL; struct kmem_cache *sysfs_dir_cachep; diff -puN fs/sysfs/sysfs.h~gregkh-driver-sysfs-crash-debugging fs/sysfs/sysfs.h --- a/fs/sysfs/sysfs.h~gregkh-driver-sysfs-crash-debugging +++ a/fs/sysfs/sysfs.h @@ -91,6 +91,7 @@ struct sysfs_addrm_cxt { extern struct sysfs_dirent sysfs_root; extern struct super_block *sysfs_sb; extern struct kmem_cache *sysfs_dir_cachep; +extern struct vfsmount *sysfs_mount; /* * dir.c diff -puN include/linux/sysfs.h~gregkh-driver-sysfs-crash-debugging include/linux/sysfs.h --- a/include/linux/sysfs.h~gregkh-driver-sysfs-crash-debugging +++ a/include/linux/sysfs.h @@ -113,6 +113,7 @@ void sysfs_remove_file_from_group(struct const struct attribute *attr, const char *group); void sysfs_notify(struct kobject *kobj, char *dir, char *attr); +void sysfs_printk_last_file(void); extern int __must_check sysfs_init(void); @@ -213,6 +214,10 @@ static inline int __must_check sysfs_ini return 0; } +static inline void sysfs_printk_last_file(void) +{ +} + #endif /* CONFIG_SYSFS */ #endif /* _SYSFS_H_ */ _