[v1,10/15] auxdisplay: linedisp: Provide a small buffer in the struct linedisp
Commit Message
There is a driver that uses small buffer for the string, when we
add a new one, we may avoid duplication and use one provided by
the line display library. Allow user to skip buffer pointer when
registering a device.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/auxdisplay/line-display.c | 4 ++--
drivers/auxdisplay/line-display.h | 4 ++++
2 files changed, 6 insertions(+), 2 deletions(-)
@@ -330,8 +330,8 @@ int linedisp_register(struct linedisp *linedisp, struct device *parent,
linedisp->dev.parent = parent;
linedisp->dev.type = &linedisp_type;
linedisp->ops = ops;
- linedisp->buf = buf;
- linedisp->num_chars = num_chars;
+ linedisp->buf = buf ? buf : linedisp->curr;
+ linedisp->num_chars = buf ? num_chars : min(num_chars, LINEDISP_DEFAULT_BUF_SZ);
linedisp->scroll_rate = DEFAULT_SCROLL_RATE;
err = ida_alloc(&linedisp_id, GFP_KERNEL);
@@ -54,12 +54,15 @@ struct linedisp_ops {
void (*update)(struct linedisp *linedisp);
};
+#define LINEDISP_DEFAULT_BUF_SZ 8u
+
/**
* struct linedisp - character line display private data structure
* @dev: the line display device
* @id: instance id of this display
* @timer: timer used to implement scrolling
* @ops: character line display operations
+ * @curr: fallback buffer for the string
* @buf: pointer to the buffer for the string currently displayed
* @message: the full message to display or scroll on the display
* @num_chars: the number of characters that can be displayed
@@ -73,6 +76,7 @@ struct linedisp {
struct timer_list timer;
const struct linedisp_ops *ops;
struct linedisp_map *map;
+ char curr[LINEDISP_DEFAULT_BUF_SZ];
char *buf;
char *message;
unsigned int num_chars;