Merge tag 'v3.10.56' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / sound / core / info.c
index 5bb97e7d325a21291f979e42d7f3dc668a3cff4d..332c9a1ef173c9377d2abef4f2cb861fcfb9f166 100644 (file)
@@ -89,7 +89,7 @@ static int resize_info_buffer(struct snd_info_buffer *buffer,
        char *nbuf;
 
        nsize = PAGE_ALIGN(nsize);
-       nbuf = krealloc(buffer->buffer, nsize, GFP_KERNEL);
+       nbuf = krealloc(buffer->buffer, nsize, GFP_KERNEL | __GFP_ZERO);
        if (! nbuf)
                return -ENOMEM;
 
@@ -105,7 +105,7 @@ static int resize_info_buffer(struct snd_info_buffer *buffer,
  *
  * Outputs the string on the procfs buffer just like printf().
  *
- * Returns the size of output string.
+ * Return: The size of output string, or a negative error code.
  */
 int snd_iprintf(struct snd_info_buffer *buffer, const char *fmt, ...)
 {
@@ -153,13 +153,6 @@ EXPORT_SYMBOL(snd_seq_root);
 struct snd_info_entry *snd_oss_root;
 #endif
 
-static void snd_remove_proc_entry(struct proc_dir_entry *parent,
-                                 struct proc_dir_entry *de)
-{
-       if (de)
-               remove_proc_entry(de->name, parent);
-}
-
 static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig)
 {
        struct snd_info_private_data *data;
@@ -260,6 +253,7 @@ static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer
        struct snd_info_buffer *buf;
        ssize_t size = 0;
        loff_t pos;
+       unsigned long realloc_size;
 
        data = file->private_data;
        if (snd_BUG_ON(!data))
@@ -268,7 +262,8 @@ static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer
        pos = *offset;
        if (pos < 0 || (long) pos != pos || (ssize_t) count < 0)
                return -EIO;
-       if ((unsigned long) pos + (unsigned long) count < (unsigned long) pos)
+       realloc_size = (unsigned long) pos + (unsigned long) count;
+       if (realloc_size < (unsigned long) pos || realloc_size > UINT_MAX)
                return -EIO;
        switch (entry->content) {
        case SNDRV_INFO_CONTENT_TEXT:
@@ -310,12 +305,10 @@ static int snd_info_entry_open(struct inode *inode, struct file *file)
        struct snd_info_entry *entry;
        struct snd_info_private_data *data;
        struct snd_info_buffer *buffer;
-       struct proc_dir_entry *p;
        int mode, err;
 
        mutex_lock(&info_mutex);
-       p = PDE(inode);
-       entry = p == NULL ? NULL : (struct snd_info_entry *)p->data;
+       entry = PDE_DATA(inode);
        if (entry == NULL || ! entry->p) {
                mutex_unlock(&info_mutex);
                return -ENODEV;
@@ -353,7 +346,7 @@ static int snd_info_entry_open(struct inode *inode, struct file *file)
                                goto __nomem;
                        data->rbuffer = buffer;
                        buffer->len = PAGE_SIZE;
-                       buffer->buffer = kmalloc(buffer->len, GFP_KERNEL);
+                       buffer->buffer = kzalloc(buffer->len, GFP_KERNEL);
                        if (buffer->buffer == NULL)
                                goto __nomem;
                }
@@ -582,7 +575,7 @@ int __exit snd_info_done(void)
 #ifdef CONFIG_SND_OSSEMUL
                snd_info_free_entry(snd_oss_root);
 #endif
-               snd_remove_proc_entry(NULL, snd_proc_root);
+               proc_remove(snd_proc_root);
        }
        return 0;
 }
@@ -644,7 +637,7 @@ void snd_info_card_id_change(struct snd_card *card)
 {
        mutex_lock(&info_mutex);
        if (card->proc_root_link) {
-               snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
+               proc_remove(card->proc_root_link);
                card->proc_root_link = NULL;
        }
        if (strcmp(card->id, card->proc_root->name))
@@ -663,10 +656,8 @@ void snd_info_card_disconnect(struct snd_card *card)
        if (!card)
                return;
        mutex_lock(&info_mutex);
-       if (card->proc_root_link) {
-               snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
-               card->proc_root_link = NULL;
-       }
+       proc_remove(card->proc_root_link);
+       card->proc_root_link = NULL;
        if (card->proc_root)
                snd_info_disconnect(card->proc_root);
        mutex_unlock(&info_mutex);
@@ -690,36 +681,31 @@ int snd_info_card_free(struct snd_card *card)
  * snd_info_get_line - read one line from the procfs buffer
  * @buffer: the procfs buffer
  * @line: the buffer to store
- * @len: the max. buffer size - 1
+ * @len: the max. buffer size
  *
  * Reads one line from the buffer and stores the string.
  *
- * Returns zero if successful, or 1 if error or EOF.
+ * Return: Zero if successful, or 1 if error or EOF.
  */
 int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len)
 {
        int c = -1;
 
+       if (snd_BUG_ON(!buffer || !buffer->buffer))
+               return 1;
        if (len <= 0 || buffer->stop || buffer->error)
                return 1;
-       while (--len > 0) {
+       while (!buffer->stop) {
                c = buffer->buffer[buffer->curr++];
-               if (c == '\n') {
-                       if (buffer->curr >= buffer->size)
-                               buffer->stop = 1;
-                       break;
-               }
-               *line++ = c;
-               if (buffer->curr >= buffer->size) {
+               if (buffer->curr >= buffer->size)
                        buffer->stop = 1;
+               if (c == '\n')
                        break;
+               if (len > 1) {
+                       len--;
+                       *line++ = c;
                }
        }
-       while (c != '\n' && !buffer->stop) {
-               c = buffer->buffer[buffer->curr++];
-               if (buffer->curr >= buffer->size)
-                       buffer->stop = 1;
-       }
        *line = '\0';
        return 0;
 }
@@ -735,7 +721,7 @@ EXPORT_SYMBOL(snd_info_get_line);
  * Parses the original string and copy a token to the given
  * string buffer.
  *
- * Returns the updated pointer of the original string so that
+ * Return: The updated pointer of the original string so that
  * it can be used for the next call.
  */
 const char *snd_info_get_str(char *dest, const char *src, int len)
@@ -774,7 +760,7 @@ EXPORT_SYMBOL(snd_info_get_str);
  * Usually called from other functions such as
  * snd_info_create_card_entry().
  *
- * Returns the pointer of the new instance, or NULL on failure.
+ * Return: The pointer of the new instance, or %NULL on failure.
  */
 static struct snd_info_entry *snd_info_create_entry(const char *name)
 {
@@ -803,7 +789,7 @@ static struct snd_info_entry *snd_info_create_entry(const char *name)
  *
  * Creates a new info entry and assigns it to the given module.
  *
- * Returns the pointer of the new instance, or NULL on failure.
+ * Return: The pointer of the new instance, or %NULL on failure.
  */
 struct snd_info_entry *snd_info_create_module_entry(struct module * module,
                                               const char *name,
@@ -827,7 +813,7 @@ EXPORT_SYMBOL(snd_info_create_module_entry);
  *
  * Creates a new info entry and assigns it to the given card.
  *
- * Returns the pointer of the new instance, or NULL on failure.
+ * Return: The pointer of the new instance, or %NULL on failure.
  */
 struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card,
                                             const char *name,
@@ -858,7 +844,7 @@ static void snd_info_disconnect(struct snd_info_entry *entry)
        list_del_init(&entry->list);
        root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
        snd_BUG_ON(!root);
-       snd_remove_proc_entry(root, entry->p);
+       proc_remove(entry->p);
        entry->p = NULL;
 }
 
@@ -893,7 +879,7 @@ static int snd_info_dev_register_entry(struct snd_device *device)
  * For releasing this entry, use snd_device_free() instead of
  * snd_info_free_entry(). 
  *
- * Returns zero if successful, or a negative error code on failure.
+ * Return: Zero if successful, or a negative error code on failure.
  */
 int snd_card_proc_new(struct snd_card *card, const char *name,
                      struct snd_info_entry **entryp)
@@ -949,7 +935,7 @@ EXPORT_SYMBOL(snd_info_free_entry);
  *
  * Registers the proc info entry.
  *
- * Returns zero if successful, or a negative error code on failure.
+ * Return: Zero if successful, or a negative error code on failure.
  */
 int snd_info_register(struct snd_info_entry * entry)
 {
@@ -959,15 +945,21 @@ int snd_info_register(struct snd_info_entry * entry)
                return -ENXIO;
        root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
        mutex_lock(&info_mutex);
-       p = create_proc_entry(entry->name, entry->mode, root);
-       if (!p) {
-               mutex_unlock(&info_mutex);
-               return -ENOMEM;
+       if (S_ISDIR(entry->mode)) {
+               p = proc_mkdir_mode(entry->name, entry->mode, root);
+               if (!p) {
+                       mutex_unlock(&info_mutex);
+                       return -ENOMEM;
+               }
+       } else {
+               p = proc_create_data(entry->name, entry->mode, root,
+                                       &snd_info_entry_operations, entry);
+               if (!p) {
+                       mutex_unlock(&info_mutex);
+                       return -ENOMEM;
+               }
+               proc_set_size(p, entry->size);
        }
-       if (!S_ISDIR(entry->mode))
-               p->proc_fops = &snd_info_entry_operations;
-       p->size = entry->size;
-       p->data = entry;
        entry->p = p;
        if (entry->parent)
                list_add_tail(&entry->list, &entry->parent->children);