mtdcore.c (6988f20fe04e9ef3aea488cb8ab57fbeb78e12f0) mtdcore.c (33b53716bc4b3ff3da2bc41581226424443f9d5a)
1/*
2 * Core registration and callback routines for MTD
3 * drivers and users.
4 *
5 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
6 * Copyright © 2006 Red Hat UK Limited
7 *
8 * This program is free software; you can redistribute it and/or modify

--- 624 unchanged lines hidden (view full) ---

633 to += vecs[i].iov_len;
634 }
635 }
636 if (retlen)
637 *retlen = totlen;
638 return ret;
639}
640
1/*
2 * Core registration and callback routines for MTD
3 * drivers and users.
4 *
5 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
6 * Copyright © 2006 Red Hat UK Limited
7 *
8 * This program is free software; you can redistribute it and/or modify

--- 624 unchanged lines hidden (view full) ---

633 to += vecs[i].iov_len;
634 }
635 }
636 if (retlen)
637 *retlen = totlen;
638 return ret;
639}
640
641/**
642 * mtd_kmalloc_up_to - allocate a contiguous buffer up to the specified size
643 * @size: A pointer to the ideal or maximum size of the allocation. Points
644 * to the actual allocation size on success.
645 *
646 * This routine attempts to allocate a contiguous kernel buffer up to
647 * the specified size, backing off the size of the request exponentially
648 * until the request succeeds or until the allocation size falls below
649 * the system page size. This attempts to make sure it does not adversely
650 * impact system performance, so when allocating more than one page, we
651 * ask the memory allocator to avoid re-trying, swapping, writing back
652 * or performing I/O.
653 *
654 * Note, this function also makes sure that the allocated buffer is aligned to
655 * the MTD device's min. I/O unit, i.e. the "mtd->writesize" value.
656 *
657 * This is called, for example by mtd_{read,write} and jffs2_scan_medium,
658 * to handle smaller (i.e. degraded) buffer allocations under low- or
659 * fragmented-memory situations where such reduced allocations, from a
660 * requested ideal, are allowed.
661 *
662 * Returns a pointer to the allocated buffer on success; otherwise, NULL.
663 */
664void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size)
665{
666 gfp_t flags = __GFP_NOWARN | __GFP_WAIT |
667 __GFP_NORETRY | __GFP_NO_KSWAPD;
668 size_t min_alloc = max_t(size_t, mtd->writesize, PAGE_SIZE);
669 void *kbuf;
670
671 *size = min_t(size_t, *size, KMALLOC_MAX_SIZE);
672
673 while (*size > min_alloc) {
674 kbuf = kmalloc(*size, flags);
675 if (kbuf)
676 return kbuf;
677
678 *size >>= 1;
679 *size = ALIGN(*size, mtd->writesize);
680 }
681
682 /*
683 * For the last resort allocation allow 'kmalloc()' to do all sorts of
684 * things (write-back, dropping caches, etc) by using GFP_KERNEL.
685 */
686 return kmalloc(*size, GFP_KERNEL);
687}
688
641EXPORT_SYMBOL_GPL(add_mtd_device);
642EXPORT_SYMBOL_GPL(del_mtd_device);
643EXPORT_SYMBOL_GPL(get_mtd_device);
644EXPORT_SYMBOL_GPL(get_mtd_device_nm);
645EXPORT_SYMBOL_GPL(__get_mtd_device);
646EXPORT_SYMBOL_GPL(put_mtd_device);
647EXPORT_SYMBOL_GPL(__put_mtd_device);
648EXPORT_SYMBOL_GPL(register_mtd_user);
649EXPORT_SYMBOL_GPL(unregister_mtd_user);
650EXPORT_SYMBOL_GPL(default_mtd_writev);
689EXPORT_SYMBOL_GPL(add_mtd_device);
690EXPORT_SYMBOL_GPL(del_mtd_device);
691EXPORT_SYMBOL_GPL(get_mtd_device);
692EXPORT_SYMBOL_GPL(get_mtd_device_nm);
693EXPORT_SYMBOL_GPL(__get_mtd_device);
694EXPORT_SYMBOL_GPL(put_mtd_device);
695EXPORT_SYMBOL_GPL(__put_mtd_device);
696EXPORT_SYMBOL_GPL(register_mtd_user);
697EXPORT_SYMBOL_GPL(unregister_mtd_user);
698EXPORT_SYMBOL_GPL(default_mtd_writev);
699EXPORT_SYMBOL_GPL(mtd_kmalloc_up_to);
651
652#ifdef CONFIG_PROC_FS
653
654/*====================================================================*/
655/* Support for /proc/mtd */
656
657static struct proc_dir_entry *proc_mtd;
658

--- 112 unchanged lines hidden ---
700
701#ifdef CONFIG_PROC_FS
702
703/*====================================================================*/
704/* Support for /proc/mtd */
705
706static struct proc_dir_entry *proc_mtd;
707

--- 112 unchanged lines hidden ---