Changes in 4.9.170 ARC: u-boot args: check that magic number is correct perf/core: Restore mmap record type correctly ext4: add missing brelse() in add_new_gdb_meta_bg() ext4: report real fs size after failed resize ALSA: echoaudio: add a check for ioremap_nocache ALSA: sb8: add a check for request_region IB/mlx4: Fix race condition between catas error reset and aliasguid flows mmc: davinci: remove extraneous __init annotation ALSA: opl3: fix mismatch between snd_opl3_drum_switch definition and declaration thermal/int340x_thermal: Add additional UUIDs thermal/int340x_thermal: fix mode setting tools/power turbostat: return the exit status of a command perf config: Fix an error in the config template documentation perf config: Fix a memory leak in collect_config() perf build-id: Fix memory leak in print_sdt_events() perf top: Fix error handling in cmd_top() perf hist: Add missing map__put() in error case perf evsel: Free evsel->counts in perf_evsel__exit() perf tests: Fix a memory leak of cpu_map object in the openat_syscall_event_on_all_cpus test perf tests: Fix a memory leak in test__perf_evsel__tp_sched_test() irqchip/mbigen: Don't clear eventid when freeing an MSI x86/hpet: Prevent potential NULL pointer dereference x86/cpu/cyrix: Use correct macros for Cyrix calls on Geode processors iommu/vt-d: Check capability before disabling protected memory x86/hw_breakpoints: Make default case in hw_breakpoint_arch_parse() return an error fix incorrect error code mapping for OBJECTID_NOT_FOUND ext4: prohibit fstrim in norecovery mode gpio: pxa: handle corner case of unprobed device rsi: improve kernel thread handling to fix kernel panic 9p: do not trust pdu content for stat item size 9p locks: add mount option for lock retry interval f2fs: fix to do sanity check with current segment number serial: uartps: console_setup() can't be placed to init section HID: i2c-hid: override HID descriptors for certain devices ARM: samsung: Limit SAMSUNG_PM_CHECK config option to non-Exynos platforms ACPI / SBS: Fix GPE storm on recent MacBookPro's cifs: fallback to older infolevels on findfirst queryinfo retry kernel: hung_task.c: disable on suspend crypto: sha256/arm - fix crash bug in Thumb2 build crypto: sha512/arm - fix crash bug in Thumb2 build iommu/dmar: Fix buffer overflow during PCI bus notification soc/tegra: pmc: Drop locking from tegra_powergate_is_powered() lkdtm: Add tests for NULL pointer dereference ARM: 8839/1: kprobe: make patch_lock a raw_spinlock_t appletalk: Fix use-after-free in atalk_proc_exit lib/div64.c: off by one in shift include/linux/swap.h: use offsetof() instead of custom __swapoffset macro tpm/tpm_crb: Avoid unaligned reads in crb_recv() net: stmmac: Set dma ring length before enabling the DMA appletalk: Fix compile regression Linux 4.9.170 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
186 lines
4.1 KiB
C
186 lines
4.1 KiB
C
/*
|
|
* Copyright (C) 2003 Bernardo Innocenti <bernie@develer.com>
|
|
*
|
|
* Based on former do_div() implementation from asm-parisc/div64.h:
|
|
* Copyright (C) 1999 Hewlett-Packard Co
|
|
* Copyright (C) 1999 David Mosberger-Tang <davidm@hpl.hp.com>
|
|
*
|
|
*
|
|
* Generic C version of 64bit/32bit division and modulo, with
|
|
* 64bit result and 32bit remainder.
|
|
*
|
|
* The fast case for (n>>32 == 0) is handled inline by do_div().
|
|
*
|
|
* Code generated for this function might be very inefficient
|
|
* for some CPUs. __div64_32() can be overridden by linking arch-specific
|
|
* assembly versions such as arch/ppc/lib/div64.S and arch/sh/lib/div64.S
|
|
* or by defining a preprocessor macro in arch/include/asm/div64.h.
|
|
*/
|
|
|
|
#include <linux/export.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/math64.h>
|
|
|
|
/* Not needed on 64bit architectures */
|
|
#if BITS_PER_LONG == 32
|
|
|
|
#ifndef __div64_32
|
|
uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
|
|
{
|
|
uint64_t rem = *n;
|
|
uint64_t b = base;
|
|
uint64_t res, d = 1;
|
|
uint32_t high = rem >> 32;
|
|
|
|
/* Reduce the thing a bit first */
|
|
res = 0;
|
|
if (high >= base) {
|
|
high /= base;
|
|
res = (uint64_t) high << 32;
|
|
rem -= (uint64_t) (high*base) << 32;
|
|
}
|
|
|
|
while ((int64_t)b > 0 && b < rem) {
|
|
b = b+b;
|
|
d = d+d;
|
|
}
|
|
|
|
do {
|
|
if (rem >= b) {
|
|
rem -= b;
|
|
res += d;
|
|
}
|
|
b >>= 1;
|
|
d >>= 1;
|
|
} while (d);
|
|
|
|
*n = res;
|
|
return rem;
|
|
}
|
|
EXPORT_SYMBOL(__div64_32);
|
|
#endif
|
|
|
|
#ifndef div_s64_rem
|
|
s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
|
|
{
|
|
u64 quotient;
|
|
|
|
if (dividend < 0) {
|
|
quotient = div_u64_rem(-dividend, abs(divisor), (u32 *)remainder);
|
|
*remainder = -*remainder;
|
|
if (divisor > 0)
|
|
quotient = -quotient;
|
|
} else {
|
|
quotient = div_u64_rem(dividend, abs(divisor), (u32 *)remainder);
|
|
if (divisor < 0)
|
|
quotient = -quotient;
|
|
}
|
|
return quotient;
|
|
}
|
|
EXPORT_SYMBOL(div_s64_rem);
|
|
#endif
|
|
|
|
/**
|
|
* div64_u64_rem - unsigned 64bit divide with 64bit divisor and remainder
|
|
* @dividend: 64bit dividend
|
|
* @divisor: 64bit divisor
|
|
* @remainder: 64bit remainder
|
|
*
|
|
* This implementation is a comparable to algorithm used by div64_u64.
|
|
* But this operation, which includes math for calculating the remainder,
|
|
* is kept distinct to avoid slowing down the div64_u64 operation on 32bit
|
|
* systems.
|
|
*/
|
|
#ifndef div64_u64_rem
|
|
u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
|
|
{
|
|
u32 high = divisor >> 32;
|
|
u64 quot;
|
|
|
|
if (high == 0) {
|
|
u32 rem32;
|
|
quot = div_u64_rem(dividend, divisor, &rem32);
|
|
*remainder = rem32;
|
|
} else {
|
|
int n = fls(high);
|
|
quot = div_u64(dividend >> n, divisor >> n);
|
|
|
|
if (quot != 0)
|
|
quot--;
|
|
|
|
*remainder = dividend - quot * divisor;
|
|
if (*remainder >= divisor) {
|
|
quot++;
|
|
*remainder -= divisor;
|
|
}
|
|
}
|
|
|
|
return quot;
|
|
}
|
|
EXPORT_SYMBOL(div64_u64_rem);
|
|
#endif
|
|
|
|
/**
|
|
* div64_u64 - unsigned 64bit divide with 64bit divisor
|
|
* @dividend: 64bit dividend
|
|
* @divisor: 64bit divisor
|
|
*
|
|
* This implementation is a modified version of the algorithm proposed
|
|
* by the book 'Hacker's Delight'. The original source and full proof
|
|
* can be found here and is available for use without restriction.
|
|
*
|
|
* 'http://www.hackersdelight.org/hdcodetxt/divDouble.c.txt'
|
|
*/
|
|
#ifndef div64_u64
|
|
u64 div64_u64(u64 dividend, u64 divisor)
|
|
{
|
|
u32 high = divisor >> 32;
|
|
u64 quot;
|
|
|
|
if (high == 0) {
|
|
quot = div_u64(dividend, divisor);
|
|
} else {
|
|
int n = fls(high);
|
|
quot = div_u64(dividend >> n, divisor >> n);
|
|
|
|
if (quot != 0)
|
|
quot--;
|
|
if ((dividend - quot * divisor) >= divisor)
|
|
quot++;
|
|
}
|
|
|
|
return quot;
|
|
}
|
|
EXPORT_SYMBOL(div64_u64);
|
|
#endif
|
|
|
|
/**
|
|
* div64_s64 - signed 64bit divide with 64bit divisor
|
|
* @dividend: 64bit dividend
|
|
* @divisor: 64bit divisor
|
|
*/
|
|
#ifndef div64_s64
|
|
s64 div64_s64(s64 dividend, s64 divisor)
|
|
{
|
|
s64 quot, t;
|
|
|
|
quot = div64_u64(abs(dividend), abs(divisor));
|
|
t = (dividend ^ divisor) >> 63;
|
|
|
|
return (quot ^ t) - t;
|
|
}
|
|
EXPORT_SYMBOL(div64_s64);
|
|
#endif
|
|
|
|
#endif /* BITS_PER_LONG == 32 */
|
|
|
|
/*
|
|
* Iterative div/mod for use when dividend is not expected to be much
|
|
* bigger than divisor.
|
|
*/
|
|
u32 iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder)
|
|
{
|
|
return __iter_div_u64_rem(dividend, divisor, remainder);
|
|
}
|
|
EXPORT_SYMBOL(iter_div_u64_rem);
|