/* * rl6231.c - RL6231 class device shared support * * Copyright 2014 Realtek Semiconductor Corp. * * Author: Oder Chiou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include #include #include "rl6231.h" /** * rl6231_get_pre_div - Return the value of pre divider. * * @map: map for setting. * @reg: register. * @sft: shift. * * Return the value of pre divider from given register value. * Return negative error code for unexpected register value. */ int rl6231_get_pre_div(struct regmap *map, unsigned int reg, int sft) { int pd, val; regmap_read(map, reg, &val); val = (val >> sft) & 0x7; switch (val) { case 0: case 1: case 2: case 3: pd = val + 1; break; case 4: pd = 6; break; case 5: pd = 8; break; case 6: pd = 12; break; case 7: pd = 16; break; default: pd = -EINVAL; break; } return pd; } EXPORT_SYMBOL_GPL(rl6231_get_pre_div); /** * rl6231_calc_dmic_clk - Calculate the frequency divider parameter of dmic. * * @rate: base clock rate. * * Choose divider parameter that gives the highest possible DMIC frequency in * 1MHz - 3MHz range. */ int rl6231_calc_dmic_clk(int rate) { int div[] = {2, 3, 4, 6, 8, 12}; int i; if (rate < 1000000 * div[0]) { pr_warn("Base clock rate %d is too low\n", rate); return -EINVAL; } for (i = 0; i < ARRAY_SIZE(div); i++) { if ((div[i] % 3) == 0) continue; /* find divider that gives DMIC frequency below 3.072MHz */ if (3072000 * div[i] >= rate) return i; } pr_warn("Base clock rate %d is too high\n", rate); return -EINVAL; } EXPORT_SYMBOL_GPL(rl6231_calc_dmic_clk); struct pll_calc_map { unsigned int pll_in; unsigned int pll_out; int k; int n; int m; bool m_bp; }; static const struct pll_calc_map pll_preset_table[] = { {19200000, 4096000, 23, 14, 1, false}, {19200000, 24576000, 3, 30, 3, false}, }; /** * rl6231_pll_calc - Calcualte PLL M/N/K code. * @freq_in: external clock provided to codec. * @freq_out: target clock which codec works on. * @pll_code: Pointer to structure with M, N, K and bypass flag. * * Calcualte M/N/K code to configure PLL for codec. * * Returns 0 for success or negative error code. */ int rl6231_pll_calc(const unsigned int freq_in, const unsigned int freq_out, struct rl6231_pll_code *pll_code) { int max_n = RL6231_PLL_N_MAX, max_m = RL6231_PLL_M_MAX; int i, k, red, n_t, pll_out, in_t, out_t; int n = 0, m = 0, m_t = 0; int red_t = abs(freq_out - freq_in); bool bypass = false; if (RL6231_PLL_INP_MAX < freq_in || RL6231_PLL_INP_MIN > freq_in) return -EINVAL; for (i = 0; i < ARRAY_SIZE(pll_preset_table); i++) { if (freq_in == pll_preset_table[i].pll_in && freq_out == pll_preset_table[i].pll_out) { k = pll_preset_table[i].k; m = pll_preset_table[i].m; n = pll_preset_table[i].n; bypass = pll_preset_table[i].m_bp; pr_debug("Use preset PLL parameter table\n"); goto code_find; } } k = 100000000 / freq_out - 2; if (k > RL6231_PLL_K_MAX) k = RL6231_PLL_K_MAX; for (n_t = 0; n_t <= max_n; n_t++) { in_t = freq_in / (k + 2); pll_out = freq_out / (n_t + 2); if (in_t < 0) continue; if (in_t == pll_out) { bypass = true; n = n_t; goto code_find; } red = abs(in_t - pll_out); if (red < red_t) { bypass = true; n = n_t; m = m_t; if (red == 0) goto code_find; red_t = red; } for (m_t = 0; m_t <= max_m; m_t++) { out_t = in_t / (m_t + 2); red = abs(out_t - pll_out); if (red < red_t) { bypass = false; n = n_t; m = m_t; if (red == 0) goto code_find; red_t = red; } } } pr_debug("Only get approximation about PLL\n"); code_find: pll_code->m_bp = bypass; pll_code->m_code = m; pll_code->n_code = n; pll_code->k_code = k; return 0; } EXPORT_SYMBOL_GPL(rl6231_pll_calc); int rl6231_get_clk_info(int sclk, int rate) { int i, pd[] = {1, 2, 3, 4, 6, 8, 12, 16}; if (sclk <= 0 || rate <= 0) return -EINVAL; rate = rate << 8; for (i = 0; i < ARRAY_SIZE(pd); i++) if (sclk == rate * pd[i]) return i; return -EINVAL; } EXPORT_SYMBOL_GPL(rl6231_get_clk_info); MODULE_DESCRIPTION("RL6231 class device shared support"); MODULE_AUTHOR("Oder Chiou "); MODULE_LICENSE("GPL v2"); olspan='2' class='oid'>b2504a5dbef3305ef41988ad270b0e8ec289331c (patch) tree361fc2c2a0a52a5804a32058f981ff9862a4d3bc /net parent160ca0142431c19386db976302fd4b07c587f651 (diff)
net: reduce skb_warn_bad_offload() noise
Dmitry reported warnings occurring in __skb_gso_segment() [1] All SKB_GSO_DODGY producers can allow user space to feed packets that trigger the current check. We could prevent them from doing so, rejecting packets, but this might add regressions to existing programs. It turns out our SKB_GSO_DODGY handlers properly set up checksum information that is needed anyway when packets needs to be segmented. By checking again skb_needs_check() after skb_mac_gso_segment(), we should remove these pesky warnings, at a very minor cost. With help from Willem de Bruijn [1] WARNING: CPU: 1 PID: 6768 at net/core/dev.c:2439 skb_warn_bad_offload+0x2af/0x390 net/core/dev.c:2434 lo: caps=(0x000000a2803b7c69, 0x0000000000000000) len=138 data_len=0 gso_size=15883 gso_type=4 ip_summed=0 Kernel panic - not syncing: panic_on_warn set ... CPU: 1 PID: 6768 Comm: syz-executor1 Not tainted 4.9.0 #5 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 ffff8801c063ecd8 ffffffff82346bdf ffffffff00000001 1ffff100380c7d2e ffffed00380c7d26 0000000041b58ab3 ffffffff84b37e38 ffffffff823468f1 ffffffff84820740 ffffffff84f289c0 dffffc0000000000 ffff8801c063ee20 Call Trace: [<ffffffff82346bdf>] __dump_stack lib/dump_stack.c:15 [inline] [<ffffffff82346bdf>] dump_stack+0x2ee/0x3ef lib/dump_stack.c:51 [<ffffffff81827e34>] panic+0x1fb/0x412 kernel/panic.c:179 [<ffffffff8141f704>] __warn+0x1c4/0x1e0 kernel/panic.c:542 [<ffffffff8141f7e5>] warn_slowpath_fmt+0xc5/0x100 kernel/panic.c:565 [<ffffffff8356cbaf>] skb_warn_bad_offload+0x2af/0x390 net/core/dev.c:2434 [<ffffffff83585cd2>] __skb_gso_segment+0x482/0x780 net/core/dev.c:2706 [<ffffffff83586f19>] skb_gso_segment include/linux/netdevice.h:3985 [inline] [<ffffffff83586f19>] validate_xmit_skb+0x5c9/0xc20 net/core/dev.c:2969 [<ffffffff835892bb>] __dev_queue_xmit+0xe6b/0x1e70 net/core/dev.c:3383 [<ffffffff8358a2d7>] dev_queue_xmit+0x17/0x20 net/core/dev.c:3424 [<ffffffff83ad161d>] packet_snd net/packet/af_packet.c:2930 [inline] [<ffffffff83ad161d>] packet_sendmsg+0x32ed/0x4d30 net/packet/af_packet.c:2955 [<ffffffff834f0aaa>] sock_sendmsg_nosec net/socket.c:621 [inline] [<ffffffff834f0aaa>] sock_sendmsg+0xca/0x110 net/socket.c:631 [<ffffffff834f329a>] ___sys_sendmsg+0x8fa/0x9f0 net/socket.c:1954 [<ffffffff834f5e58>] __sys_sendmsg+0x138/0x300 net/socket.c:1988 [<ffffffff834f604d>] SYSC_sendmsg net/socket.c:1999 [inline] [<ffffffff834f604d>] SyS_sendmsg+0x2d/0x50 net/socket.c:1995 [<ffffffff84371941>] entry_SYSCALL_64_fastpath+0x1f/0xc2 Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Dmitry Vyukov <dvyukov@google.com> Cc: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/core/dev.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/net/core/dev.c b/net/core/dev.c