Changeset 772 for GPL/trunk/lib32/misc.c


Ignore:
Timestamp:
Apr 19, 2025, 8:08:37 PM (4 months ago)
Author:
David Azarewicz
Message:

Merge in changes from 6.6-LTS branch.
Fixed additional 25+ problems.

Location:
GPL/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk

  • GPL/trunk/lib32/misc.c

    r679 r772  
    2828#include <linux/init.h>
    2929#include <linux/fs.h>
     30#include <linux/of.h>
    3031#include <linux/poll.h>
    3132#define CONFIG_PROC_FS 1
     
    3940#include <linux/firmware.h>
    4041#include <linux/ctype.h>
     42#include <linux/math64.h>
    4143#include <dbgos2.h>
    4244
    4345void StringOut(char *DbgStr);
     46extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
    4447
    4548struct new_utsname system_utsname = {0};
     
    784787        free_pages((unsigned long) ptr, pg);
    785788}
     789
     790/**
     791 * of_node_put() - Decrement refcount of a node
     792 * @node:       Node to dec refcount, NULL is supported to simplify writing of
     793 *              callers
     794 */
     795void of_node_put(struct device_node *node)
     796{
     797        if (node)
     798                kobject_put(&node->kobj);
     799}
     800
     801/**
     802 * sysfs_streq - return true if strings are equal, modulo trailing newline
     803 * @s1: one string
     804 * @s2: another string
     805 *
     806 * This routine returns true iff two strings are equal, treating both
     807 * NUL and newline-then-NUL as equivalent string terminations.  It's
     808 * geared for use with sysfs input strings, which generally terminate
     809 * with newlines but are compared against values without newlines.
     810 */
     811bool sysfs_streq(const char *s1, const char *s2)
     812{
     813        while (*s1 && *s1 == *s2) {
     814                s1++;
     815                s2++;
     816        }
     817
     818        if (*s1 == *s2)
     819                return true;
     820        if (!*s1 && *s2 == '\n' && !s2[1])
     821                return true;
     822        if (*s1 == '\n' && !s1[1] && !*s2)
     823                return true;
     824        return false;
     825}
     826EXPORT_SYMBOL(sysfs_streq);
     827
     828u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
     829{
     830        u32 high = divisor >> 32;
     831        u64 quot;
     832
     833        if (high == 0) {
     834                u32 rem32;
     835                quot = div_u64_rem(dividend, divisor, &rem32);
     836                *remainder = rem32;
     837        } else {
     838                int n = fls(high);
     839                quot = div_u64(dividend >> n, divisor >> n);
     840
     841                if (quot != 0)
     842                        quot--;
     843
     844                *remainder = dividend - quot * divisor;
     845                if (*remainder >= divisor) {
     846                        quot++;
     847                        *remainder -= divisor;
     848                }
     849        }
     850
     851        return quot;
     852}
     853
     854/**
     855 * memset32() - Fill a memory area with a uint32_t
     856 * @s: Pointer to the start of the area.
     857 * @v: The value to fill the area with
     858 * @count: The number of values to store
     859 *
     860 * Differs from memset() in that it fills with a uint32_t instead
     861 * of a byte.  Remember that @count is the number of uint32_ts to
     862 * store, not the number of bytes.
     863 */
     864void *memset32(uint32_t *s, uint32_t v, size_t count)
     865{
     866        uint32_t *xs = s;
     867
     868        while (count--)
     869                *xs++ = v;
     870        return s;
     871}
     872EXPORT_SYMBOL(memset32);
     873
     874/**
     875 *      sysfs_emit - scnprintf equivalent, aware of PAGE_SIZE buffer.
     876 *      @buf:   start of PAGE_SIZE buffer.
     877 *      @fmt:   format
     878 *      @...:   optional arguments to @format
     879 *
     880 *
     881 * Returns number of characters written to @buf.
     882 */
     883int sysfs_emit(char *buf, const char *fmt, ...)
     884{
     885        va_list args;
     886        int len;
     887
     888#ifdef NOT_USED
     889        if (WARN(!buf || offset_in_page(buf),
     890                 "invalid sysfs_emit: buf:%p\n", buf))
     891                return 0;
     892#endif
     893
     894        va_start(args, fmt);
     895        len = vscnprintf(buf, PAGE_SIZE, fmt, args);
     896        va_end(args);
     897
     898        return len;
     899}
     900EXPORT_SYMBOL_GPL(sysfs_emit);
     901
     902/**
     903 *      sysfs_emit_at - scnprintf equivalent, aware of PAGE_SIZE buffer.
     904 *      @buf:   start of PAGE_SIZE buffer.
     905 *      @at:    offset in @buf to start write in bytes
     906 *              @at must be >= 0 && < PAGE_SIZE
     907 *      @fmt:   format
     908 *      @...:   optional arguments to @fmt
     909 *
     910 *
     911 * Returns number of characters written starting at &@buf[@at].
     912 */
     913int sysfs_emit_at(char *buf, int at, const char *fmt, ...)
     914{
     915        va_list args;
     916        int len;
     917
     918#ifdef NOT_USED
     919        if (WARN(!buf || offset_in_page(buf) || at < 0 || at >= PAGE_SIZE,
     920                 "invalid sysfs_emit_at: buf:%p at:%d\n", buf, at))
     921                return 0;
     922#endif
     923
     924        va_start(args, fmt);
     925        len = vscnprintf(buf + at, PAGE_SIZE - at, fmt, args);
     926        va_end(args);
     927
     928        return len;
     929}
     930EXPORT_SYMBOL_GPL(sysfs_emit_at);
Note: See TracChangeset for help on using the changeset viewer.