Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: tty: Add a function to insert a string of characters with the same flag

The USB drivers often want to insert a series of bytes all with the same
flag set - provide a helper for this case.

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Alan Cox and committed by
Greg Kroah-Hartman
2832fc11 e4a3d946

+12 -6
+6 -5
drivers/char/tty_buffer.c
··· 231 231 EXPORT_SYMBOL_GPL(tty_buffer_request_room); 232 232 233 233 /** 234 - * tty_insert_flip_string - Add characters to the tty buffer 234 + * tty_insert_flip_string_fixed_flag - Add characters to the tty buffer 235 235 * @tty: tty structure 236 236 * @chars: characters 237 + * @flag: flag value for each character 237 238 * @size: size 238 239 * 239 240 * Queue a series of bytes to the tty buffering. All the characters ··· 243 242 * Locking: Called functions may take tty->buf.lock 244 243 */ 245 244 246 - int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars, 247 - size_t size) 245 + int tty_insert_flip_string_fixed_flag(struct tty_struct *tty, 246 + const unsigned char *chars, char flag, size_t size) 248 247 { 249 248 int copied = 0; 250 249 do { ··· 254 253 if (unlikely(space == 0)) 255 254 break; 256 255 memcpy(tb->char_buf_ptr + tb->used, chars, space); 257 - memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space); 256 + memset(tb->flag_buf_ptr + tb->used, flag, space); 258 257 tb->used += space; 259 258 copied += space; 260 259 chars += space; ··· 263 262 } while (unlikely(size > copied)); 264 263 return copied; 265 264 } 266 - EXPORT_SYMBOL(tty_insert_flip_string); 265 + EXPORT_SYMBOL(tty_insert_flip_string_fixed_flag); 267 266 268 267 /** 269 268 * tty_insert_flip_string_flags - Add characters to the tty buffer
+6 -1
include/linux/tty_flip.h
··· 2 2 #define _LINUX_TTY_FLIP_H 3 3 4 4 extern int tty_buffer_request_room(struct tty_struct *tty, size_t size); 5 - extern int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars, size_t size); 6 5 extern int tty_insert_flip_string_flags(struct tty_struct *tty, const unsigned char *chars, const char *flags, size_t size); 6 + extern int tty_insert_flip_string_fixed_flag(struct tty_struct *tty, const unsigned char *chars, char flag, size_t size); 7 7 extern int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, size_t size); 8 8 extern int tty_prepare_flip_string_flags(struct tty_struct *tty, unsigned char **chars, char **flags, size_t size); 9 9 void tty_schedule_flip(struct tty_struct *tty); ··· 18 18 return 1; 19 19 } 20 20 return tty_insert_flip_string_flags(tty, &ch, &flag, 1); 21 + } 22 + 23 + static inline int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars, size_t size) 24 + { 25 + return tty_insert_flip_string_fixed_flag(tty, chars, TTY_NORMAL, size); 21 26 } 22 27 23 28 #endif /* _LINUX_TTY_FLIP_H */