#
# http://userweb.kernel.org/~akpm/mmotm/broken-out/gregkh-driver-driver-core-debug-for-bad-dev_attr_show-return-value.patch
#
# From akpm@linux-foundation.org  Wed Mar 12 14:43:19 2008
# From: Andrew Morton <akpm@linux-foundation.org>
# Date: Tue, 04 Mar 2008 15:09:07 -0800
# Subject: driver core: debug for bad dev_attr_show() return value.
# To: greg@kroah.com
# Cc: akpm@linux-foundation.org, balajirrao@gmail.com
# Message-ID: <200803042309.m24N9701001984@imap1.linux-foundation.org>
#
#
# From: Andrew Morton <akpm@linux-foundation.org>
# 
# Try to find the culprit who caused
# http://bugzilla.kernel.org/show_bug.cgi?id=10150
# 
# Cc: <balajirrao@gmail.com>
# Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
# Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
#
# ---
# drivers/base/core.c |    5 +++++
# fs/sysfs/file.c     |    8 +++++++-
# 2 files changed, 12 insertions(+), 1 deletion(-)
#
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -19,6 +19,7 @@
 #include <linux/kdev_t.h>
 #include <linux/notifier.h>
 #include <linux/genhd.h>
+#include <linux/kallsyms.h>
 #include <asm/semaphore.h>
 
 #include "base.h"
@@ -68,6 +69,10 @@ static ssize_t dev_attr_show(struct kobj
 
 	if (dev_attr->show)
 		ret = dev_attr->show(dev, dev_attr, buf);
+	if (ret >= (ssize_t)PAGE_SIZE) {
+		print_symbol("dev_attr_show: %s returned bad count\n",
+				(unsigned long)dev_attr->show);
+	}
 	return ret;
 }
 
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -12,6 +12,7 @@
 
 #include <linux/module.h>
 #include <linux/kobject.h>
+#include <linux/kallsyms.h>
 #include <linux/namei.h>
 #include <linux/poll.h>
 #include <linux/list.h>
@@ -86,7 +87,12 @@ static int fill_read_buffer(struct dentr
 	 * The code works fine with PAGE_SIZE return but it's likely to
 	 * indicate truncated result or overflow in normal use cases.
 	 */
-	BUG_ON(count >= (ssize_t)PAGE_SIZE);
+	if (count >= (ssize_t)PAGE_SIZE) {
+		print_symbol("fill_read_buffer: %s returned bad count\n",
+			(unsigned long)ops->show);
+		/* Try to struggle along */
+		count = PAGE_SIZE - 1;
+	}
 	if (count >= 0) {
 		buffer->needs_read_fill = 0;
 		buffer->count = count;
