Magellan Linux

Contents of /trunk/kernel-alx-legacy/patches-4.9/0158-4.9.59-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3608 - (show annotations) (download)
Fri Aug 14 07:34:29 2020 UTC (3 years, 8 months ago) by niro
File size: 79183 byte(s)
-added kerenl-alx-legacy pkg
1 diff --git a/Makefile b/Makefile
2 index 32686667bb7e..900cd7c3a9ee 100644
3 --- a/Makefile
4 +++ b/Makefile
5 @@ -1,6 +1,6 @@
6 VERSION = 4
7 PATCHLEVEL = 9
8 -SUBLEVEL = 58
9 +SUBLEVEL = 59
10 EXTRAVERSION =
11 NAME = Roaring Lionus
12
13 diff --git a/arch/parisc/kernel/syscall.S b/arch/parisc/kernel/syscall.S
14 index 23de307c3052..41e60a9c7db2 100644
15 --- a/arch/parisc/kernel/syscall.S
16 +++ b/arch/parisc/kernel/syscall.S
17 @@ -742,7 +742,7 @@ lws_compare_and_swap_2:
18 10: ldd 0(%r25), %r25
19 11: ldd 0(%r24), %r24
20 #else
21 - /* Load new value into r22/r23 - high/low */
22 + /* Load old value into r22/r23 - high/low */
23 10: ldw 0(%r25), %r22
24 11: ldw 4(%r25), %r23
25 /* Load new value into fr4 for atomic store later */
26 @@ -834,11 +834,11 @@ cas2_action:
27 copy %r0, %r28
28 #else
29 /* Compare first word */
30 -19: ldw,ma 0(%r26), %r29
31 +19: ldw 0(%r26), %r29
32 sub,= %r29, %r22, %r0
33 b,n cas2_end
34 /* Compare second word */
35 -20: ldw,ma 4(%r26), %r29
36 +20: ldw 4(%r26), %r29
37 sub,= %r29, %r23, %r0
38 b,n cas2_end
39 /* Perform the store */
40 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
41 index cdc0deab00c9..13dbcc0f9d03 100644
42 --- a/arch/x86/kernel/cpu/microcode/intel.c
43 +++ b/arch/x86/kernel/cpu/microcode/intel.c
44 @@ -34,6 +34,7 @@
45 #include <linux/mm.h>
46
47 #include <asm/microcode_intel.h>
48 +#include <asm/intel-family.h>
49 #include <asm/processor.h>
50 #include <asm/tlbflush.h>
51 #include <asm/setup.h>
52 @@ -1046,6 +1047,18 @@ static int get_ucode_fw(void *to, const void *from, size_t n)
53 return 0;
54 }
55
56 +static bool is_blacklisted(unsigned int cpu)
57 +{
58 + struct cpuinfo_x86 *c = &cpu_data(cpu);
59 +
60 + if (c->x86 == 6 && c->x86_model == INTEL_FAM6_BROADWELL_X) {
61 + pr_err_once("late loading on model 79 is disabled.\n");
62 + return true;
63 + }
64 +
65 + return false;
66 +}
67 +
68 static enum ucode_state request_microcode_fw(int cpu, struct device *device,
69 bool refresh_fw)
70 {
71 @@ -1054,6 +1067,9 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
72 const struct firmware *firmware;
73 enum ucode_state ret;
74
75 + if (is_blacklisted(cpu))
76 + return UCODE_NFOUND;
77 +
78 sprintf(name, "intel-ucode/%02x-%02x-%02x",
79 c->x86, c->x86_model, c->x86_mask);
80
81 @@ -1078,6 +1094,9 @@ static int get_ucode_user(void *to, const void *from, size_t n)
82 static enum ucode_state
83 request_microcode_user(int cpu, const void __user *buf, size_t size)
84 {
85 + if (is_blacklisted(cpu))
86 + return UCODE_NFOUND;
87 +
88 return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
89 }
90
91 diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c
92 index af4cd8649117..d140d8bb2c96 100644
93 --- a/crypto/asymmetric_keys/pkcs7_parser.c
94 +++ b/crypto/asymmetric_keys/pkcs7_parser.c
95 @@ -88,6 +88,9 @@ static int pkcs7_check_authattrs(struct pkcs7_message *msg)
96 bool want = false;
97
98 sinfo = msg->signed_infos;
99 + if (!sinfo)
100 + goto inconsistent;
101 +
102 if (sinfo->authattrs) {
103 want = true;
104 msg->have_authattrs = true;
105 diff --git a/drivers/bus/mvebu-mbus.c b/drivers/bus/mvebu-mbus.c
106 index c7f396903184..70db4d5638a6 100644
107 --- a/drivers/bus/mvebu-mbus.c
108 +++ b/drivers/bus/mvebu-mbus.c
109 @@ -720,7 +720,7 @@ mvebu_mbus_default_setup_cpu_target(struct mvebu_mbus_state *mbus)
110 if (mbus->hw_io_coherency)
111 w->mbus_attr |= ATTR_HW_COHERENCY;
112 w->base = base & DDR_BASE_CS_LOW_MASK;
113 - w->size = (size | ~DDR_SIZE_MASK) + 1;
114 + w->size = (u64)(size | ~DDR_SIZE_MASK) + 1;
115 }
116 }
117 mvebu_mbus_dram_info.num_cs = cs;
118 diff --git a/drivers/clocksource/cs5535-clockevt.c b/drivers/clocksource/cs5535-clockevt.c
119 index 9a7e37cf56b0..e1d7373e63e0 100644
120 --- a/drivers/clocksource/cs5535-clockevt.c
121 +++ b/drivers/clocksource/cs5535-clockevt.c
122 @@ -117,7 +117,8 @@ static irqreturn_t mfgpt_tick(int irq, void *dev_id)
123 /* Turn off the clock (and clear the event) */
124 disable_timer(cs5535_event_clock);
125
126 - if (clockevent_state_shutdown(&cs5535_clockevent))
127 + if (clockevent_state_detached(&cs5535_clockevent) ||
128 + clockevent_state_shutdown(&cs5535_clockevent))
129 return IRQ_HANDLED;
130
131 /* Clear the counter */
132 diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/bsp/g84.c b/drivers/gpu/drm/nouveau/nvkm/engine/bsp/g84.c
133 index 8e2e24a74774..44e116f7880d 100644
134 --- a/drivers/gpu/drm/nouveau/nvkm/engine/bsp/g84.c
135 +++ b/drivers/gpu/drm/nouveau/nvkm/engine/bsp/g84.c
136 @@ -39,5 +39,5 @@ int
137 g84_bsp_new(struct nvkm_device *device, int index, struct nvkm_engine **pengine)
138 {
139 return nvkm_xtensa_new_(&g84_bsp, device, index,
140 - true, 0x103000, pengine);
141 + device->chipset != 0x92, 0x103000, pengine);
142 }
143 diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/base.c
144 index 5df9669ea39c..240872a27c37 100644
145 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/base.c
146 +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/base.c
147 @@ -240,6 +240,8 @@ nvkm_vm_unmap_pgt(struct nvkm_vm *vm, int big, u32 fpde, u32 lpde)
148 mmu->func->map_pgt(vpgd->obj, pde, vpgt->mem);
149 }
150
151 + mmu->func->flush(vm);
152 +
153 nvkm_memory_del(&pgt);
154 }
155 }
156 diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c
157 index 8477292e92c8..7aea28815d99 100644
158 --- a/drivers/i2c/busses/i2c-ismt.c
159 +++ b/drivers/i2c/busses/i2c-ismt.c
160 @@ -340,12 +340,15 @@ static int ismt_process_desc(const struct ismt_desc *desc,
161 data->word = dma_buffer[0] | (dma_buffer[1] << 8);
162 break;
163 case I2C_SMBUS_BLOCK_DATA:
164 - case I2C_SMBUS_I2C_BLOCK_DATA:
165 if (desc->rxbytes != dma_buffer[0] + 1)
166 return -EMSGSIZE;
167
168 memcpy(data->block, dma_buffer, desc->rxbytes);
169 break;
170 + case I2C_SMBUS_I2C_BLOCK_DATA:
171 + memcpy(&data->block[1], dma_buffer, desc->rxbytes);
172 + data->block[0] = desc->rxbytes;
173 + break;
174 }
175 return 0;
176 }
177 diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
178 index c21ca7bf2efe..8f1c5f24c1df 100644
179 --- a/drivers/i2c/busses/i2c-piix4.c
180 +++ b/drivers/i2c/busses/i2c-piix4.c
181 @@ -94,6 +94,12 @@
182 #define SB800_PIIX4_PORT_IDX_ALT 0x2e
183 #define SB800_PIIX4_PORT_IDX_SEL 0x2f
184 #define SB800_PIIX4_PORT_IDX_MASK 0x06
185 +#define SB800_PIIX4_PORT_IDX_SHIFT 1
186 +
187 +/* On kerncz, SmBus0Sel is at bit 20:19 of PMx00 DecodeEn */
188 +#define SB800_PIIX4_PORT_IDX_KERNCZ 0x02
189 +#define SB800_PIIX4_PORT_IDX_MASK_KERNCZ 0x18
190 +#define SB800_PIIX4_PORT_IDX_SHIFT_KERNCZ 3
191
192 /* insmod parameters */
193
194 @@ -149,6 +155,8 @@ static const struct dmi_system_id piix4_dmi_ibm[] = {
195 */
196 static DEFINE_MUTEX(piix4_mutex_sb800);
197 static u8 piix4_port_sel_sb800;
198 +static u8 piix4_port_mask_sb800;
199 +static u8 piix4_port_shift_sb800;
200 static const char *piix4_main_port_names_sb800[PIIX4_MAX_ADAPTERS] = {
201 " port 0", " port 2", " port 3", " port 4"
202 };
203 @@ -347,7 +355,19 @@ static int piix4_setup_sb800(struct pci_dev *PIIX4_dev,
204
205 /* Find which register is used for port selection */
206 if (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD) {
207 - piix4_port_sel_sb800 = SB800_PIIX4_PORT_IDX_ALT;
208 + switch (PIIX4_dev->device) {
209 + case PCI_DEVICE_ID_AMD_KERNCZ_SMBUS:
210 + piix4_port_sel_sb800 = SB800_PIIX4_PORT_IDX_KERNCZ;
211 + piix4_port_mask_sb800 = SB800_PIIX4_PORT_IDX_MASK_KERNCZ;
212 + piix4_port_shift_sb800 = SB800_PIIX4_PORT_IDX_SHIFT_KERNCZ;
213 + break;
214 + case PCI_DEVICE_ID_AMD_HUDSON2_SMBUS:
215 + default:
216 + piix4_port_sel_sb800 = SB800_PIIX4_PORT_IDX_ALT;
217 + piix4_port_mask_sb800 = SB800_PIIX4_PORT_IDX_MASK;
218 + piix4_port_shift_sb800 = SB800_PIIX4_PORT_IDX_SHIFT;
219 + break;
220 + }
221 } else {
222 mutex_lock(&piix4_mutex_sb800);
223 outb_p(SB800_PIIX4_PORT_IDX_SEL, SB800_PIIX4_SMB_IDX);
224 @@ -355,6 +375,8 @@ static int piix4_setup_sb800(struct pci_dev *PIIX4_dev,
225 piix4_port_sel_sb800 = (port_sel & 0x01) ?
226 SB800_PIIX4_PORT_IDX_ALT :
227 SB800_PIIX4_PORT_IDX;
228 + piix4_port_mask_sb800 = SB800_PIIX4_PORT_IDX_MASK;
229 + piix4_port_shift_sb800 = SB800_PIIX4_PORT_IDX_SHIFT;
230 mutex_unlock(&piix4_mutex_sb800);
231 }
232
233 @@ -616,8 +638,8 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr,
234 smba_en_lo = inb_p(SB800_PIIX4_SMB_IDX + 1);
235
236 port = adapdata->port;
237 - if ((smba_en_lo & SB800_PIIX4_PORT_IDX_MASK) != port)
238 - outb_p((smba_en_lo & ~SB800_PIIX4_PORT_IDX_MASK) | port,
239 + if ((smba_en_lo & piix4_port_mask_sb800) != port)
240 + outb_p((smba_en_lo & ~piix4_port_mask_sb800) | port,
241 SB800_PIIX4_SMB_IDX + 1);
242
243 retval = piix4_access(adap, addr, flags, read_write,
244 @@ -706,7 +728,7 @@ static int piix4_add_adapter(struct pci_dev *dev, unsigned short smba,
245
246 adapdata->smba = smba;
247 adapdata->sb800_main = sb800_main;
248 - adapdata->port = port << 1;
249 + adapdata->port = port << piix4_port_shift_sb800;
250
251 /* set up the sysfs linkage to our parent device */
252 adap->dev.parent = &dev->dev;
253 diff --git a/drivers/iio/dummy/iio_simple_dummy_events.c b/drivers/iio/dummy/iio_simple_dummy_events.c
254 index ed63ffd849f8..7ec2a0bb0807 100644
255 --- a/drivers/iio/dummy/iio_simple_dummy_events.c
256 +++ b/drivers/iio/dummy/iio_simple_dummy_events.c
257 @@ -72,6 +72,7 @@ int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
258 st->event_en = state;
259 else
260 return -EINVAL;
261 + break;
262 default:
263 return -EINVAL;
264 }
265 diff --git a/drivers/net/can/usb/esd_usb2.c b/drivers/net/can/usb/esd_usb2.c
266 index be928ce62d32..9fdb0f0bfa06 100644
267 --- a/drivers/net/can/usb/esd_usb2.c
268 +++ b/drivers/net/can/usb/esd_usb2.c
269 @@ -333,7 +333,7 @@ static void esd_usb2_rx_can_msg(struct esd_usb2_net_priv *priv,
270 }
271
272 cf->can_id = id & ESD_IDMASK;
273 - cf->can_dlc = get_can_dlc(msg->msg.rx.dlc);
274 + cf->can_dlc = get_can_dlc(msg->msg.rx.dlc & ~ESD_RTR);
275
276 if (id & ESD_EXTID)
277 cf->can_id |= CAN_EFF_FLAG;
278 diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
279 index 05369dc9dd09..eea9aea14b00 100644
280 --- a/drivers/net/can/usb/gs_usb.c
281 +++ b/drivers/net/can/usb/gs_usb.c
282 @@ -375,6 +375,8 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
283
284 gs_free_tx_context(txc);
285
286 + atomic_dec(&dev->active_tx_urbs);
287 +
288 netif_wake_queue(netdev);
289 }
290
291 @@ -463,14 +465,6 @@ static void gs_usb_xmit_callback(struct urb *urb)
292 urb->transfer_buffer_length,
293 urb->transfer_buffer,
294 urb->transfer_dma);
295 -
296 - atomic_dec(&dev->active_tx_urbs);
297 -
298 - if (!netif_device_present(netdev))
299 - return;
300 -
301 - if (netif_queue_stopped(netdev))
302 - netif_wake_queue(netdev);
303 }
304
305 static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb,
306 diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
307 index 79c081fd560f..6afcf86b9ba2 100644
308 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
309 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
310 @@ -429,7 +429,8 @@ void brcmf_fweh_process_event(struct brcmf_pub *drvr,
311 if (code != BRCMF_E_IF && !fweh->evt_handler[code])
312 return;
313
314 - if (datalen > BRCMF_DCMD_MAXLEN)
315 + if (datalen > BRCMF_DCMD_MAXLEN ||
316 + datalen + sizeof(*event_packet) > packet_len)
317 return;
318
319 if (in_interrupt())
320 diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c
321 index b3aab2fe96eb..ef685465f80a 100644
322 --- a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c
323 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c
324 @@ -14764,8 +14764,8 @@ static void wlc_phy_ipa_restore_tx_digi_filts_nphy(struct brcms_phy *pi)
325 }
326
327 static void
328 -wlc_phy_set_rfseq_nphy(struct brcms_phy *pi, u8 cmd, u8 *events, u8 *dlys,
329 - u8 len)
330 +wlc_phy_set_rfseq_nphy(struct brcms_phy *pi, u8 cmd, const u8 *events,
331 + const u8 *dlys, u8 len)
332 {
333 u32 t1_offset, t2_offset;
334 u8 ctr;
335 @@ -15240,16 +15240,16 @@ static void wlc_phy_workarounds_nphy_gainctrl_2057_rev5(struct brcms_phy *pi)
336 static void wlc_phy_workarounds_nphy_gainctrl_2057_rev6(struct brcms_phy *pi)
337 {
338 u16 currband;
339 - s8 lna1G_gain_db_rev7[] = { 9, 14, 19, 24 };
340 - s8 *lna1_gain_db = NULL;
341 - s8 *lna1_gain_db_2 = NULL;
342 - s8 *lna2_gain_db = NULL;
343 - s8 tiaA_gain_db_rev7[] = { -9, -6, -3, 0, 3, 3, 3, 3, 3, 3 };
344 - s8 *tia_gain_db;
345 - s8 tiaA_gainbits_rev7[] = { 0, 1, 2, 3, 4, 4, 4, 4, 4, 4 };
346 - s8 *tia_gainbits;
347 - u16 rfseqA_init_gain_rev7[] = { 0x624f, 0x624f };
348 - u16 *rfseq_init_gain;
349 + static const s8 lna1G_gain_db_rev7[] = { 9, 14, 19, 24 };
350 + const s8 *lna1_gain_db = NULL;
351 + const s8 *lna1_gain_db_2 = NULL;
352 + const s8 *lna2_gain_db = NULL;
353 + static const s8 tiaA_gain_db_rev7[] = { -9, -6, -3, 0, 3, 3, 3, 3, 3, 3 };
354 + const s8 *tia_gain_db;
355 + static const s8 tiaA_gainbits_rev7[] = { 0, 1, 2, 3, 4, 4, 4, 4, 4, 4 };
356 + const s8 *tia_gainbits;
357 + static const u16 rfseqA_init_gain_rev7[] = { 0x624f, 0x624f };
358 + const u16 *rfseq_init_gain;
359 u16 init_gaincode;
360 u16 clip1hi_gaincode;
361 u16 clip1md_gaincode = 0;
362 @@ -15310,10 +15310,9 @@ static void wlc_phy_workarounds_nphy_gainctrl_2057_rev6(struct brcms_phy *pi)
363
364 if ((freq <= 5080) || (freq == 5825)) {
365
366 - s8 lna1A_gain_db_rev7[] = { 11, 16, 20, 24 };
367 - s8 lna1A_gain_db_2_rev7[] = {
368 - 11, 17, 22, 25};
369 - s8 lna2A_gain_db_rev7[] = { -1, 6, 10, 14 };
370 + static const s8 lna1A_gain_db_rev7[] = { 11, 16, 20, 24 };
371 + static const s8 lna1A_gain_db_2_rev7[] = { 11, 17, 22, 25};
372 + static const s8 lna2A_gain_db_rev7[] = { -1, 6, 10, 14 };
373
374 crsminu_th = 0x3e;
375 lna1_gain_db = lna1A_gain_db_rev7;
376 @@ -15321,10 +15320,9 @@ static void wlc_phy_workarounds_nphy_gainctrl_2057_rev6(struct brcms_phy *pi)
377 lna2_gain_db = lna2A_gain_db_rev7;
378 } else if ((freq >= 5500) && (freq <= 5700)) {
379
380 - s8 lna1A_gain_db_rev7[] = { 11, 17, 21, 25 };
381 - s8 lna1A_gain_db_2_rev7[] = {
382 - 12, 18, 22, 26};
383 - s8 lna2A_gain_db_rev7[] = { 1, 8, 12, 16 };
384 + static const s8 lna1A_gain_db_rev7[] = { 11, 17, 21, 25 };
385 + static const s8 lna1A_gain_db_2_rev7[] = { 12, 18, 22, 26};
386 + static const s8 lna2A_gain_db_rev7[] = { 1, 8, 12, 16 };
387
388 crsminu_th = 0x45;
389 clip1md_gaincode_B = 0x14;
390 @@ -15335,10 +15333,9 @@ static void wlc_phy_workarounds_nphy_gainctrl_2057_rev6(struct brcms_phy *pi)
391 lna2_gain_db = lna2A_gain_db_rev7;
392 } else {
393
394 - s8 lna1A_gain_db_rev7[] = { 12, 18, 22, 26 };
395 - s8 lna1A_gain_db_2_rev7[] = {
396 - 12, 18, 22, 26};
397 - s8 lna2A_gain_db_rev7[] = { -1, 6, 10, 14 };
398 + static const s8 lna1A_gain_db_rev7[] = { 12, 18, 22, 26 };
399 + static const s8 lna1A_gain_db_2_rev7[] = { 12, 18, 22, 26};
400 + static const s8 lna2A_gain_db_rev7[] = { -1, 6, 10, 14 };
401
402 crsminu_th = 0x41;
403 lna1_gain_db = lna1A_gain_db_rev7;
404 @@ -15450,65 +15447,65 @@ static void wlc_phy_workarounds_nphy_gainctrl(struct brcms_phy *pi)
405 NPHY_RFSEQ_CMD_CLR_HIQ_DIS,
406 NPHY_RFSEQ_CMD_SET_HPF_BW
407 };
408 - u8 rfseq_updategainu_dlys[] = { 10, 30, 1 };
409 - s8 lna1G_gain_db[] = { 7, 11, 16, 23 };
410 - s8 lna1G_gain_db_rev4[] = { 8, 12, 17, 25 };
411 - s8 lna1G_gain_db_rev5[] = { 9, 13, 18, 26 };
412 - s8 lna1G_gain_db_rev6[] = { 8, 13, 18, 25 };
413 - s8 lna1G_gain_db_rev6_224B0[] = { 10, 14, 19, 27 };
414 - s8 lna1A_gain_db[] = { 7, 11, 17, 23 };
415 - s8 lna1A_gain_db_rev4[] = { 8, 12, 18, 23 };
416 - s8 lna1A_gain_db_rev5[] = { 6, 10, 16, 21 };
417 - s8 lna1A_gain_db_rev6[] = { 6, 10, 16, 21 };
418 - s8 *lna1_gain_db = NULL;
419 - s8 lna2G_gain_db[] = { -5, 6, 10, 14 };
420 - s8 lna2G_gain_db_rev5[] = { -3, 7, 11, 16 };
421 - s8 lna2G_gain_db_rev6[] = { -5, 6, 10, 14 };
422 - s8 lna2G_gain_db_rev6_224B0[] = { -5, 6, 10, 15 };
423 - s8 lna2A_gain_db[] = { -6, 2, 6, 10 };
424 - s8 lna2A_gain_db_rev4[] = { -5, 2, 6, 10 };
425 - s8 lna2A_gain_db_rev5[] = { -7, 0, 4, 8 };
426 - s8 lna2A_gain_db_rev6[] = { -7, 0, 4, 8 };
427 - s8 *lna2_gain_db = NULL;
428 - s8 tiaG_gain_db[] = {
429 + static const u8 rfseq_updategainu_dlys[] = { 10, 30, 1 };
430 + static const s8 lna1G_gain_db[] = { 7, 11, 16, 23 };
431 + static const s8 lna1G_gain_db_rev4[] = { 8, 12, 17, 25 };
432 + static const s8 lna1G_gain_db_rev5[] = { 9, 13, 18, 26 };
433 + static const s8 lna1G_gain_db_rev6[] = { 8, 13, 18, 25 };
434 + static const s8 lna1G_gain_db_rev6_224B0[] = { 10, 14, 19, 27 };
435 + static const s8 lna1A_gain_db[] = { 7, 11, 17, 23 };
436 + static const s8 lna1A_gain_db_rev4[] = { 8, 12, 18, 23 };
437 + static const s8 lna1A_gain_db_rev5[] = { 6, 10, 16, 21 };
438 + static const s8 lna1A_gain_db_rev6[] = { 6, 10, 16, 21 };
439 + const s8 *lna1_gain_db = NULL;
440 + static const s8 lna2G_gain_db[] = { -5, 6, 10, 14 };
441 + static const s8 lna2G_gain_db_rev5[] = { -3, 7, 11, 16 };
442 + static const s8 lna2G_gain_db_rev6[] = { -5, 6, 10, 14 };
443 + static const s8 lna2G_gain_db_rev6_224B0[] = { -5, 6, 10, 15 };
444 + static const s8 lna2A_gain_db[] = { -6, 2, 6, 10 };
445 + static const s8 lna2A_gain_db_rev4[] = { -5, 2, 6, 10 };
446 + static const s8 lna2A_gain_db_rev5[] = { -7, 0, 4, 8 };
447 + static const s8 lna2A_gain_db_rev6[] = { -7, 0, 4, 8 };
448 + const s8 *lna2_gain_db = NULL;
449 + static const s8 tiaG_gain_db[] = {
450 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A };
451 - s8 tiaA_gain_db[] = {
452 + static const s8 tiaA_gain_db[] = {
453 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 };
454 - s8 tiaA_gain_db_rev4[] = {
455 + static const s8 tiaA_gain_db_rev4[] = {
456 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d };
457 - s8 tiaA_gain_db_rev5[] = {
458 + static const s8 tiaA_gain_db_rev5[] = {
459 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d };
460 - s8 tiaA_gain_db_rev6[] = {
461 + static const s8 tiaA_gain_db_rev6[] = {
462 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d };
463 - s8 *tia_gain_db;
464 - s8 tiaG_gainbits[] = {
465 + const s8 *tia_gain_db;
466 + static const s8 tiaG_gainbits[] = {
467 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 };
468 - s8 tiaA_gainbits[] = {
469 + static const s8 tiaA_gainbits[] = {
470 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06 };
471 - s8 tiaA_gainbits_rev4[] = {
472 + static const s8 tiaA_gainbits_rev4[] = {
473 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04 };
474 - s8 tiaA_gainbits_rev5[] = {
475 + static const s8 tiaA_gainbits_rev5[] = {
476 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04 };
477 - s8 tiaA_gainbits_rev6[] = {
478 + static const s8 tiaA_gainbits_rev6[] = {
479 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04 };
480 - s8 *tia_gainbits;
481 - s8 lpf_gain_db[] = { 0x00, 0x06, 0x0c, 0x12, 0x12, 0x12 };
482 - s8 lpf_gainbits[] = { 0x00, 0x01, 0x02, 0x03, 0x03, 0x03 };
483 - u16 rfseqG_init_gain[] = { 0x613f, 0x613f, 0x613f, 0x613f };
484 - u16 rfseqG_init_gain_rev4[] = { 0x513f, 0x513f, 0x513f, 0x513f };
485 - u16 rfseqG_init_gain_rev5[] = { 0x413f, 0x413f, 0x413f, 0x413f };
486 - u16 rfseqG_init_gain_rev5_elna[] = {
487 + const s8 *tia_gainbits;
488 + static const s8 lpf_gain_db[] = { 0x00, 0x06, 0x0c, 0x12, 0x12, 0x12 };
489 + static const s8 lpf_gainbits[] = { 0x00, 0x01, 0x02, 0x03, 0x03, 0x03 };
490 + static const u16 rfseqG_init_gain[] = { 0x613f, 0x613f, 0x613f, 0x613f };
491 + static const u16 rfseqG_init_gain_rev4[] = { 0x513f, 0x513f, 0x513f, 0x513f };
492 + static const u16 rfseqG_init_gain_rev5[] = { 0x413f, 0x413f, 0x413f, 0x413f };
493 + static const u16 rfseqG_init_gain_rev5_elna[] = {
494 0x013f, 0x013f, 0x013f, 0x013f };
495 - u16 rfseqG_init_gain_rev6[] = { 0x513f, 0x513f };
496 - u16 rfseqG_init_gain_rev6_224B0[] = { 0x413f, 0x413f };
497 - u16 rfseqG_init_gain_rev6_elna[] = { 0x113f, 0x113f };
498 - u16 rfseqA_init_gain[] = { 0x516f, 0x516f, 0x516f, 0x516f };
499 - u16 rfseqA_init_gain_rev4[] = { 0x614f, 0x614f, 0x614f, 0x614f };
500 - u16 rfseqA_init_gain_rev4_elna[] = {
501 + static const u16 rfseqG_init_gain_rev6[] = { 0x513f, 0x513f };
502 + static const u16 rfseqG_init_gain_rev6_224B0[] = { 0x413f, 0x413f };
503 + static const u16 rfseqG_init_gain_rev6_elna[] = { 0x113f, 0x113f };
504 + static const u16 rfseqA_init_gain[] = { 0x516f, 0x516f, 0x516f, 0x516f };
505 + static const u16 rfseqA_init_gain_rev4[] = { 0x614f, 0x614f, 0x614f, 0x614f };
506 + static const u16 rfseqA_init_gain_rev4_elna[] = {
507 0x314f, 0x314f, 0x314f, 0x314f };
508 - u16 rfseqA_init_gain_rev5[] = { 0x714f, 0x714f, 0x714f, 0x714f };
509 - u16 rfseqA_init_gain_rev6[] = { 0x714f, 0x714f };
510 - u16 *rfseq_init_gain;
511 + static const u16 rfseqA_init_gain_rev5[] = { 0x714f, 0x714f, 0x714f, 0x714f };
512 + static const u16 rfseqA_init_gain_rev6[] = { 0x714f, 0x714f };
513 + const u16 *rfseq_init_gain;
514 u16 initG_gaincode = 0x627e;
515 u16 initG_gaincode_rev4 = 0x527e;
516 u16 initG_gaincode_rev5 = 0x427e;
517 @@ -15538,10 +15535,10 @@ static void wlc_phy_workarounds_nphy_gainctrl(struct brcms_phy *pi)
518 u16 clip1mdA_gaincode_rev6 = 0x2084;
519 u16 clip1md_gaincode = 0;
520 u16 clip1loG_gaincode = 0x0074;
521 - u16 clip1loG_gaincode_rev5[] = {
522 + static const u16 clip1loG_gaincode_rev5[] = {
523 0x0062, 0x0064, 0x006a, 0x106a, 0x106c, 0x1074, 0x107c, 0x207c
524 };
525 - u16 clip1loG_gaincode_rev6[] = {
526 + static const u16 clip1loG_gaincode_rev6[] = {
527 0x106a, 0x106c, 0x1074, 0x107c, 0x007e, 0x107e, 0x207e, 0x307e
528 };
529 u16 clip1loG_gaincode_rev6_224B0 = 0x1074;
530 @@ -16066,7 +16063,7 @@ static void wlc_phy_workarounds_nphy_gainctrl(struct brcms_phy *pi)
531
532 static void wlc_phy_workarounds_nphy(struct brcms_phy *pi)
533 {
534 - u8 rfseq_rx2tx_events[] = {
535 + static const u8 rfseq_rx2tx_events[] = {
536 NPHY_RFSEQ_CMD_NOP,
537 NPHY_RFSEQ_CMD_RXG_FBW,
538 NPHY_RFSEQ_CMD_TR_SWITCH,
539 @@ -16076,7 +16073,7 @@ static void wlc_phy_workarounds_nphy(struct brcms_phy *pi)
540 NPHY_RFSEQ_CMD_EXT_PA
541 };
542 u8 rfseq_rx2tx_dlys[] = { 8, 6, 6, 2, 4, 60, 1 };
543 - u8 rfseq_tx2rx_events[] = {
544 + static const u8 rfseq_tx2rx_events[] = {
545 NPHY_RFSEQ_CMD_NOP,
546 NPHY_RFSEQ_CMD_EXT_PA,
547 NPHY_RFSEQ_CMD_TX_GAIN,
548 @@ -16085,8 +16082,8 @@ static void wlc_phy_workarounds_nphy(struct brcms_phy *pi)
549 NPHY_RFSEQ_CMD_RXG_FBW,
550 NPHY_RFSEQ_CMD_CLR_HIQ_DIS
551 };
552 - u8 rfseq_tx2rx_dlys[] = { 8, 6, 2, 4, 4, 6, 1 };
553 - u8 rfseq_tx2rx_events_rev3[] = {
554 + static const u8 rfseq_tx2rx_dlys[] = { 8, 6, 2, 4, 4, 6, 1 };
555 + static const u8 rfseq_tx2rx_events_rev3[] = {
556 NPHY_REV3_RFSEQ_CMD_EXT_PA,
557 NPHY_REV3_RFSEQ_CMD_INT_PA_PU,
558 NPHY_REV3_RFSEQ_CMD_TX_GAIN,
559 @@ -16096,7 +16093,7 @@ static void wlc_phy_workarounds_nphy(struct brcms_phy *pi)
560 NPHY_REV3_RFSEQ_CMD_CLR_HIQ_DIS,
561 NPHY_REV3_RFSEQ_CMD_END
562 };
563 - u8 rfseq_tx2rx_dlys_rev3[] = { 8, 4, 2, 2, 4, 4, 6, 1 };
564 + static const u8 rfseq_tx2rx_dlys_rev3[] = { 8, 4, 2, 2, 4, 4, 6, 1 };
565 u8 rfseq_rx2tx_events_rev3[] = {
566 NPHY_REV3_RFSEQ_CMD_NOP,
567 NPHY_REV3_RFSEQ_CMD_RXG_FBW,
568 @@ -16110,7 +16107,7 @@ static void wlc_phy_workarounds_nphy(struct brcms_phy *pi)
569 };
570 u8 rfseq_rx2tx_dlys_rev3[] = { 8, 6, 6, 4, 4, 18, 42, 1, 1 };
571
572 - u8 rfseq_rx2tx_events_rev3_ipa[] = {
573 + static const u8 rfseq_rx2tx_events_rev3_ipa[] = {
574 NPHY_REV3_RFSEQ_CMD_NOP,
575 NPHY_REV3_RFSEQ_CMD_RXG_FBW,
576 NPHY_REV3_RFSEQ_CMD_TR_SWITCH,
577 @@ -16121,15 +16118,15 @@ static void wlc_phy_workarounds_nphy(struct brcms_phy *pi)
578 NPHY_REV3_RFSEQ_CMD_INT_PA_PU,
579 NPHY_REV3_RFSEQ_CMD_END
580 };
581 - u8 rfseq_rx2tx_dlys_rev3_ipa[] = { 8, 6, 6, 4, 4, 16, 43, 1, 1 };
582 - u16 rfseq_rx2tx_dacbufpu_rev7[] = { 0x10f, 0x10f };
583 + static const u8 rfseq_rx2tx_dlys_rev3_ipa[] = { 8, 6, 6, 4, 4, 16, 43, 1, 1 };
584 + static const u16 rfseq_rx2tx_dacbufpu_rev7[] = { 0x10f, 0x10f };
585
586 s16 alpha0, alpha1, alpha2;
587 s16 beta0, beta1, beta2;
588 u32 leg_data_weights, ht_data_weights, nss1_data_weights,
589 stbc_data_weights;
590 u8 chan_freq_range = 0;
591 - u16 dac_control = 0x0002;
592 + static const u16 dac_control = 0x0002;
593 u16 aux_adc_vmid_rev7_core0[] = { 0x8e, 0x96, 0x96, 0x96 };
594 u16 aux_adc_vmid_rev7_core1[] = { 0x8f, 0x9f, 0x9f, 0x96 };
595 u16 aux_adc_vmid_rev4[] = { 0xa2, 0xb4, 0xb4, 0x89 };
596 @@ -16139,8 +16136,8 @@ static void wlc_phy_workarounds_nphy(struct brcms_phy *pi)
597 u16 aux_adc_gain_rev4[] = { 0x02, 0x02, 0x02, 0x00 };
598 u16 aux_adc_gain_rev3[] = { 0x02, 0x02, 0x02, 0x00 };
599 u16 *aux_adc_gain;
600 - u16 sk_adc_vmid[] = { 0xb4, 0xb4, 0xb4, 0x24 };
601 - u16 sk_adc_gain[] = { 0x02, 0x02, 0x02, 0x02 };
602 + static const u16 sk_adc_vmid[] = { 0xb4, 0xb4, 0xb4, 0x24 };
603 + static const u16 sk_adc_gain[] = { 0x02, 0x02, 0x02, 0x02 };
604 s32 min_nvar_val = 0x18d;
605 s32 min_nvar_offset_6mbps = 20;
606 u8 pdetrange;
607 @@ -16151,9 +16148,9 @@ static void wlc_phy_workarounds_nphy(struct brcms_phy *pi)
608 u16 rfseq_rx2tx_lpf_h_hpc_rev7 = 0x77;
609 u16 rfseq_tx2rx_lpf_h_hpc_rev7 = 0x77;
610 u16 rfseq_pktgn_lpf_h_hpc_rev7 = 0x77;
611 - u16 rfseq_htpktgn_lpf_hpc_rev7[] = { 0x77, 0x11, 0x11 };
612 - u16 rfseq_pktgn_lpf_hpc_rev7[] = { 0x11, 0x11 };
613 - u16 rfseq_cckpktgn_lpf_hpc_rev7[] = { 0x11, 0x11 };
614 + static const u16 rfseq_htpktgn_lpf_hpc_rev7[] = { 0x77, 0x11, 0x11 };
615 + static const u16 rfseq_pktgn_lpf_hpc_rev7[] = { 0x11, 0x11 };
616 + static const u16 rfseq_cckpktgn_lpf_hpc_rev7[] = { 0x11, 0x11 };
617 u16 ipalvlshift_3p3_war_en = 0;
618 u16 rccal_bcap_val, rccal_scap_val;
619 u16 rccal_tx20_11b_bcap = 0;
620 @@ -24291,13 +24288,13 @@ static void wlc_phy_update_txcal_ladder_nphy(struct brcms_phy *pi, u16 core)
621 u16 bbmult;
622 u16 tblentry;
623
624 - struct nphy_txiqcal_ladder ladder_lo[] = {
625 + static const struct nphy_txiqcal_ladder ladder_lo[] = {
626 {3, 0}, {4, 0}, {6, 0}, {9, 0}, {13, 0}, {18, 0},
627 {25, 0}, {25, 1}, {25, 2}, {25, 3}, {25, 4}, {25, 5},
628 {25, 6}, {25, 7}, {35, 7}, {50, 7}, {71, 7}, {100, 7}
629 };
630
631 - struct nphy_txiqcal_ladder ladder_iq[] = {
632 + static const struct nphy_txiqcal_ladder ladder_iq[] = {
633 {3, 0}, {4, 0}, {6, 0}, {9, 0}, {13, 0}, {18, 0},
634 {25, 0}, {35, 0}, {50, 0}, {71, 0}, {100, 0}, {100, 1},
635 {100, 2}, {100, 3}, {100, 4}, {100, 5}, {100, 6}, {100, 7}
636 @@ -25773,67 +25770,67 @@ wlc_phy_cal_txiqlo_nphy(struct brcms_phy *pi, struct nphy_txgains target_gain,
637 u16 cal_gain[2];
638 struct nphy_iqcal_params cal_params[2];
639 u32 tbl_len;
640 - void *tbl_ptr;
641 + const void *tbl_ptr;
642 bool ladder_updated[2];
643 u8 mphase_cal_lastphase = 0;
644 int bcmerror = 0;
645 bool phyhang_avoid_state = false;
646
647 - u16 tbl_tx_iqlo_cal_loft_ladder_20[] = {
648 + static const u16 tbl_tx_iqlo_cal_loft_ladder_20[] = {
649 0x0300, 0x0500, 0x0700, 0x0900, 0x0d00, 0x1100, 0x1900, 0x1901,
650 0x1902,
651 0x1903, 0x1904, 0x1905, 0x1906, 0x1907, 0x2407, 0x3207, 0x4607,
652 0x6407
653 };
654
655 - u16 tbl_tx_iqlo_cal_iqimb_ladder_20[] = {
656 + static const u16 tbl_tx_iqlo_cal_iqimb_ladder_20[] = {
657 0x0200, 0x0300, 0x0600, 0x0900, 0x0d00, 0x1100, 0x1900, 0x2400,
658 0x3200,
659 0x4600, 0x6400, 0x6401, 0x6402, 0x6403, 0x6404, 0x6405, 0x6406,
660 0x6407
661 };
662
663 - u16 tbl_tx_iqlo_cal_loft_ladder_40[] = {
664 + static const u16 tbl_tx_iqlo_cal_loft_ladder_40[] = {
665 0x0200, 0x0300, 0x0400, 0x0700, 0x0900, 0x0c00, 0x1200, 0x1201,
666 0x1202,
667 0x1203, 0x1204, 0x1205, 0x1206, 0x1207, 0x1907, 0x2307, 0x3207,
668 0x4707
669 };
670
671 - u16 tbl_tx_iqlo_cal_iqimb_ladder_40[] = {
672 + static const u16 tbl_tx_iqlo_cal_iqimb_ladder_40[] = {
673 0x0100, 0x0200, 0x0400, 0x0700, 0x0900, 0x0c00, 0x1200, 0x1900,
674 0x2300,
675 0x3200, 0x4700, 0x4701, 0x4702, 0x4703, 0x4704, 0x4705, 0x4706,
676 0x4707
677 };
678
679 - u16 tbl_tx_iqlo_cal_startcoefs[] = {
680 + static const u16 tbl_tx_iqlo_cal_startcoefs[] = {
681 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
682 0x0000
683 };
684
685 - u16 tbl_tx_iqlo_cal_cmds_fullcal[] = {
686 + static const u16 tbl_tx_iqlo_cal_cmds_fullcal[] = {
687 0x8123, 0x8264, 0x8086, 0x8245, 0x8056,
688 0x9123, 0x9264, 0x9086, 0x9245, 0x9056
689 };
690
691 - u16 tbl_tx_iqlo_cal_cmds_recal[] = {
692 + static const u16 tbl_tx_iqlo_cal_cmds_recal[] = {
693 0x8101, 0x8253, 0x8053, 0x8234, 0x8034,
694 0x9101, 0x9253, 0x9053, 0x9234, 0x9034
695 };
696
697 - u16 tbl_tx_iqlo_cal_startcoefs_nphyrev3[] = {
698 + static const u16 tbl_tx_iqlo_cal_startcoefs_nphyrev3[] = {
699 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
700 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
701 0x0000
702 };
703
704 - u16 tbl_tx_iqlo_cal_cmds_fullcal_nphyrev3[] = {
705 + static const u16 tbl_tx_iqlo_cal_cmds_fullcal_nphyrev3[] = {
706 0x8434, 0x8334, 0x8084, 0x8267, 0x8056, 0x8234,
707 0x9434, 0x9334, 0x9084, 0x9267, 0x9056, 0x9234
708 };
709
710 - u16 tbl_tx_iqlo_cal_cmds_recal_nphyrev3[] = {
711 + static const u16 tbl_tx_iqlo_cal_cmds_recal_nphyrev3[] = {
712 0x8423, 0x8323, 0x8073, 0x8256, 0x8045, 0x8223,
713 0x9423, 0x9323, 0x9073, 0x9256, 0x9045, 0x9223
714 };
715 diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c
716 index 2cbef9647acc..1281ebe0c30a 100644
717 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c
718 +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c
719 @@ -1128,7 +1128,7 @@ static u8 _rtl8821ae_dbi_read(struct rtl_priv *rtlpriv, u16 addr)
720 }
721 if (0 == tmp) {
722 read_addr = REG_DBI_RDATA + addr % 4;
723 - ret = rtl_read_byte(rtlpriv, read_addr);
724 + ret = rtl_read_word(rtlpriv, read_addr);
725 }
726 return ret;
727 }
728 diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
729 index f16491c25e73..ea20b2cc189f 100644
730 --- a/drivers/usb/class/cdc-acm.c
731 +++ b/drivers/usb/class/cdc-acm.c
732 @@ -1773,6 +1773,9 @@ static const struct usb_device_id acm_ids[] = {
733 { USB_DEVICE(0xfff0, 0x0100), /* DATECS FP-2000 */
734 .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
735 },
736 + { USB_DEVICE(0x09d8, 0x0320), /* Elatec GmbH TWN3 */
737 + .driver_info = NO_UNION_NORMAL, /* has misplaced union descriptor */
738 + },
739
740 { USB_DEVICE(0x2912, 0x0001), /* ATOL FPrint */
741 .driver_info = CLEAR_HALT_CONDITIONS,
742 diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
743 index 11793386b4e9..5008f71fb08d 100644
744 --- a/drivers/usb/core/config.c
745 +++ b/drivers/usb/core/config.c
746 @@ -955,10 +955,12 @@ int usb_get_bos_descriptor(struct usb_device *dev)
747 for (i = 0; i < num; i++) {
748 buffer += length;
749 cap = (struct usb_dev_cap_header *)buffer;
750 - length = cap->bLength;
751
752 - if (total_len < length)
753 + if (total_len < sizeof(*cap) || total_len < cap->bLength) {
754 + dev->bos->desc->bNumDeviceCaps = i;
755 break;
756 + }
757 + length = cap->bLength;
758 total_len -= length;
759
760 if (cap->bDescriptorType != USB_DT_DEVICE_CAPABILITY) {
761 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
762 index 860108c46e9a..c8075eb3db26 100644
763 --- a/drivers/usb/core/devio.c
764 +++ b/drivers/usb/core/devio.c
765 @@ -1577,11 +1577,7 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
766 totlen += isopkt[u].length;
767 }
768 u *= sizeof(struct usb_iso_packet_descriptor);
769 - if (totlen <= uurb->buffer_length)
770 - uurb->buffer_length = totlen;
771 - else
772 - WARN_ONCE(1, "uurb->buffer_length is too short %d vs %d",
773 - totlen, uurb->buffer_length);
774 + uurb->buffer_length = totlen;
775 break;
776
777 default:
778 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
779 index 8127f112958e..706b3d6a7614 100644
780 --- a/drivers/usb/core/hub.c
781 +++ b/drivers/usb/core/hub.c
782 @@ -2704,13 +2704,16 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
783 if (!(portstatus & USB_PORT_STAT_CONNECTION))
784 return -ENOTCONN;
785
786 - /* bomb out completely if the connection bounced. A USB 3.0
787 - * connection may bounce if multiple warm resets were issued,
788 + /* Retry if connect change is set but status is still connected.
789 + * A USB 3.0 connection may bounce if multiple warm resets were issued,
790 * but the device may have successfully re-connected. Ignore it.
791 */
792 if (!hub_is_superspeed(hub->hdev) &&
793 - (portchange & USB_PORT_STAT_C_CONNECTION))
794 - return -ENOTCONN;
795 + (portchange & USB_PORT_STAT_C_CONNECTION)) {
796 + usb_clear_port_feature(hub->hdev, port1,
797 + USB_PORT_FEAT_C_CONNECTION);
798 + return -EAGAIN;
799 + }
800
801 if (!(portstatus & USB_PORT_STAT_ENABLE))
802 return -EBUSY;
803 diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
804 index 82806e311202..a6aaf2f193a4 100644
805 --- a/drivers/usb/core/quirks.c
806 +++ b/drivers/usb/core/quirks.c
807 @@ -221,6 +221,10 @@ static const struct usb_device_id usb_quirk_list[] = {
808 /* Corsair Strafe RGB */
809 { USB_DEVICE(0x1b1c, 0x1b20), .driver_info = USB_QUIRK_DELAY_INIT },
810
811 + /* MIDI keyboard WORLDE MINI */
812 + { USB_DEVICE(0x1c75, 0x0204), .driver_info =
813 + USB_QUIRK_CONFIG_INTF_STRINGS },
814 +
815 /* Acer C120 LED Projector */
816 { USB_DEVICE(0x1de1, 0xc102), .driver_info = USB_QUIRK_NO_LPM },
817
818 diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
819 index 82308af5801b..a7d239f5fc5f 100644
820 --- a/drivers/usb/host/xhci.c
821 +++ b/drivers/usb/host/xhci.c
822 @@ -4855,7 +4855,8 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
823 */
824 hcd->has_tt = 1;
825 } else {
826 - if (xhci->sbrn == 0x31) {
827 + /* Some 3.1 hosts return sbrn 0x30, can't rely on sbrn alone */
828 + if (xhci->sbrn == 0x31 || xhci->usb3_rhub.min_rev >= 1) {
829 xhci_info(xhci, "Host supports USB 3.1 Enhanced SuperSpeed\n");
830 hcd->speed = HCD_USB31;
831 hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS;
832 diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
833 index a6b6b1cf1317..aac28d998073 100644
834 --- a/drivers/usb/musb/musb_core.c
835 +++ b/drivers/usb/musb/musb_core.c
836 @@ -890,7 +890,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
837 */
838 if (int_usb & MUSB_INTR_RESET) {
839 handled = IRQ_HANDLED;
840 - if (devctl & MUSB_DEVCTL_HM) {
841 + if (is_host_active(musb)) {
842 /*
843 * When BABBLE happens what we can depends on which
844 * platform MUSB is running, because some platforms
845 @@ -900,9 +900,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
846 * drop the session.
847 */
848 dev_err(musb->controller, "Babble\n");
849 -
850 - if (is_host_active(musb))
851 - musb_recover_from_babble(musb);
852 + musb_recover_from_babble(musb);
853 } else {
854 musb_dbg(musb, "BUS RESET as %s",
855 usb_otg_state_string(musb->xceiv->otg->state));
856 diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
857 index 1408245be18e..3e1f3daa42f5 100644
858 --- a/drivers/usb/musb/sunxi.c
859 +++ b/drivers/usb/musb/sunxi.c
860 @@ -313,6 +313,8 @@ static int sunxi_musb_exit(struct musb *musb)
861 if (test_bit(SUNXI_MUSB_FL_HAS_SRAM, &glue->flags))
862 sunxi_sram_release(musb->controller->parent);
863
864 + devm_usb_put_phy(glue->dev, glue->xceiv);
865 +
866 return 0;
867 }
868
869 diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c
870 index 39e683096e94..45182c65fa1f 100644
871 --- a/drivers/usb/serial/metro-usb.c
872 +++ b/drivers/usb/serial/metro-usb.c
873 @@ -45,6 +45,7 @@ struct metrousb_private {
874 static const struct usb_device_id id_table[] = {
875 { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_BI) },
876 { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_UNI) },
877 + { USB_DEVICE_INTERFACE_CLASS(0x0c2e, 0x0730, 0xff) }, /* MS7820 */
878 { }, /* Terminating entry. */
879 };
880 MODULE_DEVICE_TABLE(usb, id_table);
881 diff --git a/fs/crypto/keyinfo.c b/fs/crypto/keyinfo.c
882 index bb4606368eb1..a755fa1a0017 100644
883 --- a/fs/crypto/keyinfo.c
884 +++ b/fs/crypto/keyinfo.c
885 @@ -108,6 +108,11 @@ static int validate_user_key(struct fscrypt_info *crypt_info,
886 goto out;
887 }
888 ukp = user_key_payload(keyring_key);
889 + if (!ukp) {
890 + /* key was revoked before we acquired its semaphore */
891 + res = -EKEYREVOKED;
892 + goto out;
893 + }
894 if (ukp->datalen != sizeof(struct fscrypt_key)) {
895 res = -EINVAL;
896 goto out;
897 diff --git a/fs/fscache/object-list.c b/fs/fscache/object-list.c
898 index 5d5ddaa84b21..37e0c31d284f 100644
899 --- a/fs/fscache/object-list.c
900 +++ b/fs/fscache/object-list.c
901 @@ -330,6 +330,13 @@ static void fscache_objlist_config(struct fscache_objlist_data *data)
902 rcu_read_lock();
903
904 confkey = user_key_payload(key);
905 + if (!confkey) {
906 + /* key was revoked */
907 + rcu_read_unlock();
908 + key_put(key);
909 + goto no_config;
910 + }
911 +
912 buf = confkey->data;
913
914 for (len = confkey->datalen - 1; len >= 0; len--) {
915 diff --git a/fs/xfs/libxfs/xfs_ag_resv.c b/fs/xfs/libxfs/xfs_ag_resv.c
916 index 33db69be4832..eed8f5867c46 100644
917 --- a/fs/xfs/libxfs/xfs_ag_resv.c
918 +++ b/fs/xfs/libxfs/xfs_ag_resv.c
919 @@ -157,7 +157,8 @@ __xfs_ag_resv_free(
920 trace_xfs_ag_resv_free(pag, type, 0);
921
922 resv = xfs_perag_resv(pag, type);
923 - pag->pag_mount->m_ag_max_usable += resv->ar_asked;
924 + if (pag->pag_agno == 0)
925 + pag->pag_mount->m_ag_max_usable += resv->ar_asked;
926 /*
927 * AGFL blocks are always considered "free", so whatever
928 * was reserved at mount time must be given back at umount.
929 @@ -217,7 +218,14 @@ __xfs_ag_resv_init(
930 return error;
931 }
932
933 - mp->m_ag_max_usable -= ask;
934 + /*
935 + * Reduce the maximum per-AG allocation length by however much we're
936 + * trying to reserve for an AG. Since this is a filesystem-wide
937 + * counter, we only make the adjustment for AG 0. This assumes that
938 + * there aren't any AGs hungrier for per-AG reservation than AG 0.
939 + */
940 + if (pag->pag_agno == 0)
941 + mp->m_ag_max_usable -= ask;
942
943 resv = xfs_perag_resv(pag, type);
944 resv->ar_asked = ask;
945 diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
946 index 9f06a211e157..c3702cda010a 100644
947 --- a/fs/xfs/libxfs/xfs_alloc.c
948 +++ b/fs/xfs/libxfs/xfs_alloc.c
949 @@ -1579,6 +1579,10 @@ xfs_alloc_ag_vextent_small(
950
951 bp = xfs_btree_get_bufs(args->mp, args->tp,
952 args->agno, fbno, 0);
953 + if (!bp) {
954 + error = -EFSCORRUPTED;
955 + goto error0;
956 + }
957 xfs_trans_binval(args->tp, bp);
958 }
959 args->len = 1;
960 @@ -2136,6 +2140,10 @@ xfs_alloc_fix_freelist(
961 if (error)
962 goto out_agbp_relse;
963 bp = xfs_btree_get_bufs(mp, tp, args->agno, bno, 0);
964 + if (!bp) {
965 + error = -EFSCORRUPTED;
966 + goto out_agbp_relse;
967 + }
968 xfs_trans_binval(tp, bp);
969 }
970
971 diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
972 index d2f4ab175096..7eb99701054f 100644
973 --- a/fs/xfs/libxfs/xfs_bmap.c
974 +++ b/fs/xfs/libxfs/xfs_bmap.c
975 @@ -4057,6 +4057,17 @@ xfs_trim_extent(
976 }
977 }
978
979 +/* trim extent to within eof */
980 +void
981 +xfs_trim_extent_eof(
982 + struct xfs_bmbt_irec *irec,
983 + struct xfs_inode *ip)
984 +
985 +{
986 + xfs_trim_extent(irec, 0, XFS_B_TO_FSB(ip->i_mount,
987 + i_size_read(VFS_I(ip))));
988 +}
989 +
990 /*
991 * Trim the returned map to the required bounds
992 */
993 diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h
994 index db53ac7ff6df..f1446d127120 100644
995 --- a/fs/xfs/libxfs/xfs_bmap.h
996 +++ b/fs/xfs/libxfs/xfs_bmap.h
997 @@ -196,6 +196,7 @@ void xfs_bmap_trace_exlist(struct xfs_inode *ip, xfs_extnum_t cnt,
998
999 void xfs_trim_extent(struct xfs_bmbt_irec *irec, xfs_fileoff_t bno,
1000 xfs_filblks_t len);
1001 +void xfs_trim_extent_eof(struct xfs_bmbt_irec *, struct xfs_inode *);
1002 int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd);
1003 void xfs_bmap_local_to_extents_empty(struct xfs_inode *ip, int whichfork);
1004 void xfs_bmap_add_free(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
1005 diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h
1006 index 083cdd6d6c28..ce6958b1385c 100644
1007 --- a/fs/xfs/libxfs/xfs_log_format.h
1008 +++ b/fs/xfs/libxfs/xfs_log_format.h
1009 @@ -270,6 +270,7 @@ typedef struct xfs_inode_log_format {
1010 __uint32_t ilf_fields; /* flags for fields logged */
1011 __uint16_t ilf_asize; /* size of attr d/ext/root */
1012 __uint16_t ilf_dsize; /* size of data/ext/root */
1013 + __uint32_t ilf_pad; /* pad for 64 bit boundary */
1014 __uint64_t ilf_ino; /* inode number */
1015 union {
1016 __uint32_t ilfu_rdev; /* rdev value for dev inode*/
1017 @@ -280,29 +281,17 @@ typedef struct xfs_inode_log_format {
1018 __int32_t ilf_boffset; /* off of inode in buffer */
1019 } xfs_inode_log_format_t;
1020
1021 -typedef struct xfs_inode_log_format_32 {
1022 - __uint16_t ilf_type; /* inode log item type */
1023 - __uint16_t ilf_size; /* size of this item */
1024 - __uint32_t ilf_fields; /* flags for fields logged */
1025 - __uint16_t ilf_asize; /* size of attr d/ext/root */
1026 - __uint16_t ilf_dsize; /* size of data/ext/root */
1027 - __uint64_t ilf_ino; /* inode number */
1028 - union {
1029 - __uint32_t ilfu_rdev; /* rdev value for dev inode*/
1030 - uuid_t ilfu_uuid; /* mount point value */
1031 - } ilf_u;
1032 - __int64_t ilf_blkno; /* blkno of inode buffer */
1033 - __int32_t ilf_len; /* len of inode buffer */
1034 - __int32_t ilf_boffset; /* off of inode in buffer */
1035 -} __attribute__((packed)) xfs_inode_log_format_32_t;
1036 -
1037 -typedef struct xfs_inode_log_format_64 {
1038 +/*
1039 + * Old 32 bit systems will log in this format without the 64 bit
1040 + * alignment padding. Recovery will detect this and convert it to the
1041 + * correct format.
1042 + */
1043 +struct xfs_inode_log_format_32 {
1044 __uint16_t ilf_type; /* inode log item type */
1045 __uint16_t ilf_size; /* size of this item */
1046 __uint32_t ilf_fields; /* flags for fields logged */
1047 __uint16_t ilf_asize; /* size of attr d/ext/root */
1048 __uint16_t ilf_dsize; /* size of data/ext/root */
1049 - __uint32_t ilf_pad; /* pad for 64 bit boundary */
1050 __uint64_t ilf_ino; /* inode number */
1051 union {
1052 __uint32_t ilfu_rdev; /* rdev value for dev inode*/
1053 @@ -311,7 +300,7 @@ typedef struct xfs_inode_log_format_64 {
1054 __int64_t ilf_blkno; /* blkno of inode buffer */
1055 __int32_t ilf_len; /* len of inode buffer */
1056 __int32_t ilf_boffset; /* off of inode in buffer */
1057 -} xfs_inode_log_format_64_t;
1058 +} __attribute__((packed));
1059
1060
1061 /*
1062 diff --git a/fs/xfs/xfs_acl.c b/fs/xfs/xfs_acl.c
1063 index 7034e17535de..3354140de07e 100644
1064 --- a/fs/xfs/xfs_acl.c
1065 +++ b/fs/xfs/xfs_acl.c
1066 @@ -247,6 +247,8 @@ xfs_set_mode(struct inode *inode, umode_t mode)
1067 int
1068 xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
1069 {
1070 + umode_t mode;
1071 + bool set_mode = false;
1072 int error = 0;
1073
1074 if (!acl)
1075 @@ -257,16 +259,24 @@ xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
1076 return error;
1077
1078 if (type == ACL_TYPE_ACCESS) {
1079 - umode_t mode;
1080 -
1081 error = posix_acl_update_mode(inode, &mode, &acl);
1082 if (error)
1083 return error;
1084 - error = xfs_set_mode(inode, mode);
1085 - if (error)
1086 - return error;
1087 + set_mode = true;
1088 }
1089
1090 set_acl:
1091 - return __xfs_set_acl(inode, acl, type);
1092 + error = __xfs_set_acl(inode, acl, type);
1093 + if (error)
1094 + return error;
1095 +
1096 + /*
1097 + * We set the mode after successfully updating the ACL xattr because the
1098 + * xattr update can fail at ENOSPC and we don't want to change the mode
1099 + * if the ACL update hasn't been applied.
1100 + */
1101 + if (set_mode)
1102 + error = xfs_set_mode(inode, mode);
1103 +
1104 + return error;
1105 }
1106 diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
1107 index d23889e0bedc..d31cd1ebd8e9 100644
1108 --- a/fs/xfs/xfs_aops.c
1109 +++ b/fs/xfs/xfs_aops.c
1110 @@ -335,7 +335,8 @@ xfs_end_io(
1111 error = xfs_reflink_end_cow(ip, offset, size);
1112 break;
1113 case XFS_IO_UNWRITTEN:
1114 - error = xfs_iomap_write_unwritten(ip, offset, size);
1115 + /* writeback should never update isize */
1116 + error = xfs_iomap_write_unwritten(ip, offset, size, false);
1117 break;
1118 default:
1119 ASSERT(!xfs_ioend_is_append(ioend) || ioend->io_append_trans);
1120 @@ -437,6 +438,19 @@ xfs_imap_valid(
1121 {
1122 offset >>= inode->i_blkbits;
1123
1124 + /*
1125 + * We have to make sure the cached mapping is within EOF to protect
1126 + * against eofblocks trimming on file release leaving us with a stale
1127 + * mapping. Otherwise, a page for a subsequent file extending buffered
1128 + * write could get picked up by this writeback cycle and written to the
1129 + * wrong blocks.
1130 + *
1131 + * Note that what we really want here is a generic mapping invalidation
1132 + * mechanism to protect us from arbitrary extent modifying contexts, not
1133 + * just eofblocks.
1134 + */
1135 + xfs_trim_extent_eof(imap, XFS_I(inode));
1136 +
1137 return offset >= imap->br_startoff &&
1138 offset < imap->br_startoff + imap->br_blockcount;
1139 }
1140 @@ -725,6 +739,14 @@ xfs_vm_invalidatepage(
1141 {
1142 trace_xfs_invalidatepage(page->mapping->host, page, offset,
1143 length);
1144 +
1145 + /*
1146 + * If we are invalidating the entire page, clear the dirty state from it
1147 + * so that we can check for attempts to release dirty cached pages in
1148 + * xfs_vm_releasepage().
1149 + */
1150 + if (offset == 0 && length >= PAGE_SIZE)
1151 + cancel_dirty_page(page);
1152 block_invalidatepage(page, offset, length);
1153 }
1154
1155 @@ -1180,25 +1202,27 @@ xfs_vm_releasepage(
1156 * mm accommodates an old ext3 case where clean pages might not have had
1157 * the dirty bit cleared. Thus, it can send actual dirty pages to
1158 * ->releasepage() via shrink_active_list(). Conversely,
1159 - * block_invalidatepage() can send pages that are still marked dirty
1160 - * but otherwise have invalidated buffers.
1161 + * block_invalidatepage() can send pages that are still marked dirty but
1162 + * otherwise have invalidated buffers.
1163 *
1164 * We want to release the latter to avoid unnecessary buildup of the
1165 - * LRU, skip the former and warn if we've left any lingering
1166 - * delalloc/unwritten buffers on clean pages. Skip pages with delalloc
1167 - * or unwritten buffers and warn if the page is not dirty. Otherwise
1168 - * try to release the buffers.
1169 + * LRU, so xfs_vm_invalidatepage() clears the page dirty flag on pages
1170 + * that are entirely invalidated and need to be released. Hence the
1171 + * only time we should get dirty pages here is through
1172 + * shrink_active_list() and so we can simply skip those now.
1173 + *
1174 + * warn if we've left any lingering delalloc/unwritten buffers on clean
1175 + * or invalidated pages we are about to release.
1176 */
1177 + if (PageDirty(page))
1178 + return 0;
1179 +
1180 xfs_count_page_state(page, &delalloc, &unwritten);
1181
1182 - if (delalloc) {
1183 - WARN_ON_ONCE(!PageDirty(page));
1184 + if (WARN_ON_ONCE(delalloc))
1185 return 0;
1186 - }
1187 - if (unwritten) {
1188 - WARN_ON_ONCE(!PageDirty(page));
1189 + if (WARN_ON_ONCE(unwritten))
1190 return 0;
1191 - }
1192
1193 return try_to_free_buffers(page);
1194 }
1195 @@ -1532,6 +1556,21 @@ xfs_end_io_direct_write(
1196 return 0;
1197 }
1198
1199 + if (flags & XFS_DIO_FLAG_COW)
1200 + error = xfs_reflink_end_cow(ip, offset, size);
1201 +
1202 + /*
1203 + * Unwritten conversion updates the in-core isize after extent
1204 + * conversion but before updating the on-disk size. Updating isize any
1205 + * earlier allows a racing dio read to find unwritten extents before
1206 + * they are converted.
1207 + */
1208 + if (flags & XFS_DIO_FLAG_UNWRITTEN) {
1209 + trace_xfs_end_io_direct_write_unwritten(ip, offset, size);
1210 +
1211 + return xfs_iomap_write_unwritten(ip, offset, size, true);
1212 + }
1213 +
1214 /*
1215 * We need to update the in-core inode size here so that we don't end up
1216 * with the on-disk inode size being outside the in-core inode size. We
1217 @@ -1548,13 +1587,6 @@ xfs_end_io_direct_write(
1218 i_size_write(inode, offset + size);
1219 spin_unlock(&ip->i_flags_lock);
1220
1221 - if (flags & XFS_DIO_FLAG_COW)
1222 - error = xfs_reflink_end_cow(ip, offset, size);
1223 - if (flags & XFS_DIO_FLAG_UNWRITTEN) {
1224 - trace_xfs_end_io_direct_write_unwritten(ip, offset, size);
1225 -
1226 - error = xfs_iomap_write_unwritten(ip, offset, size);
1227 - }
1228 if (flags & XFS_DIO_FLAG_APPEND) {
1229 trace_xfs_end_io_direct_write_append(ip, offset, size);
1230
1231 diff --git a/fs/xfs/xfs_attr_inactive.c b/fs/xfs/xfs_attr_inactive.c
1232 index be0b79d8900f..c6643004e583 100644
1233 --- a/fs/xfs/xfs_attr_inactive.c
1234 +++ b/fs/xfs/xfs_attr_inactive.c
1235 @@ -302,6 +302,8 @@ xfs_attr3_node_inactive(
1236 &bp, XFS_ATTR_FORK);
1237 if (error)
1238 return error;
1239 + node = bp->b_addr;
1240 + btree = dp->d_ops->node_tree_p(node);
1241 child_fsb = be32_to_cpu(btree[i + 1].before);
1242 xfs_trans_brelse(*trans, bp);
1243 }
1244 diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
1245 index 5ffefac081f7..cb62871fb91d 100644
1246 --- a/fs/xfs/xfs_bmap_util.c
1247 +++ b/fs/xfs/xfs_bmap_util.c
1248 @@ -84,6 +84,7 @@ xfs_zero_extent(
1249 GFP_NOFS, true);
1250 }
1251
1252 +#ifdef CONFIG_XFS_RT
1253 int
1254 xfs_bmap_rtalloc(
1255 struct xfs_bmalloca *ap) /* bmap alloc argument struct */
1256 @@ -195,6 +196,7 @@ xfs_bmap_rtalloc(
1257 }
1258 return 0;
1259 }
1260 +#endif /* CONFIG_XFS_RT */
1261
1262 /*
1263 * Check if the endoff is outside the last extent. If so the caller will grow
1264 @@ -1445,7 +1447,19 @@ xfs_shift_file_space(
1265 return error;
1266
1267 /*
1268 - * The extent shiting code works on extent granularity. So, if
1269 + * Clean out anything hanging around in the cow fork now that
1270 + * we've flushed all the dirty data out to disk to avoid having
1271 + * CoW extents at the wrong offsets.
1272 + */
1273 + if (xfs_is_reflink_inode(ip)) {
1274 + error = xfs_reflink_cancel_cow_range(ip, offset, NULLFILEOFF,
1275 + true);
1276 + if (error)
1277 + return error;
1278 + }
1279 +
1280 + /*
1281 + * The extent shifting code works on extent granularity. So, if
1282 * stop_fsb is not the starting block of extent, we need to split
1283 * the extent at stop_fsb.
1284 */
1285 @@ -2094,11 +2108,31 @@ xfs_swap_extents(
1286 ip->i_d.di_flags2 |= tip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK;
1287 tip->i_d.di_flags2 &= ~XFS_DIFLAG2_REFLINK;
1288 tip->i_d.di_flags2 |= f & XFS_DIFLAG2_REFLINK;
1289 + }
1290 +
1291 + /* Swap the cow forks. */
1292 + if (xfs_sb_version_hasreflink(&mp->m_sb)) {
1293 + xfs_extnum_t extnum;
1294 +
1295 + ASSERT(ip->i_cformat == XFS_DINODE_FMT_EXTENTS);
1296 + ASSERT(tip->i_cformat == XFS_DINODE_FMT_EXTENTS);
1297 +
1298 + extnum = ip->i_cnextents;
1299 + ip->i_cnextents = tip->i_cnextents;
1300 + tip->i_cnextents = extnum;
1301 +
1302 cowfp = ip->i_cowfp;
1303 ip->i_cowfp = tip->i_cowfp;
1304 tip->i_cowfp = cowfp;
1305 - xfs_inode_set_cowblocks_tag(ip);
1306 - xfs_inode_set_cowblocks_tag(tip);
1307 +
1308 + if (ip->i_cowfp && ip->i_cnextents)
1309 + xfs_inode_set_cowblocks_tag(ip);
1310 + else
1311 + xfs_inode_clear_cowblocks_tag(ip);
1312 + if (tip->i_cowfp && tip->i_cnextents)
1313 + xfs_inode_set_cowblocks_tag(tip);
1314 + else
1315 + xfs_inode_clear_cowblocks_tag(tip);
1316 }
1317
1318 xfs_trans_log_inode(tp, ip, src_log_flags);
1319 diff --git a/fs/xfs/xfs_bmap_util.h b/fs/xfs/xfs_bmap_util.h
1320 index f1005393785c..ce330f06563e 100644
1321 --- a/fs/xfs/xfs_bmap_util.h
1322 +++ b/fs/xfs/xfs_bmap_util.h
1323 @@ -28,7 +28,20 @@ struct xfs_mount;
1324 struct xfs_trans;
1325 struct xfs_bmalloca;
1326
1327 +#ifdef CONFIG_XFS_RT
1328 int xfs_bmap_rtalloc(struct xfs_bmalloca *ap);
1329 +#else /* !CONFIG_XFS_RT */
1330 +/*
1331 + * Attempts to allocate RT extents when RT is disable indicates corruption and
1332 + * should trigger a shutdown.
1333 + */
1334 +static inline int
1335 +xfs_bmap_rtalloc(struct xfs_bmalloca *ap)
1336 +{
1337 + return -EFSCORRUPTED;
1338 +}
1339 +#endif /* CONFIG_XFS_RT */
1340 +
1341 int xfs_bmap_eof(struct xfs_inode *ip, xfs_fileoff_t endoff,
1342 int whichfork, int *eof);
1343 int xfs_bmap_punch_delalloc_range(struct xfs_inode *ip,
1344 diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c
1345 index ed7ee4e8af73..bcf72970ca6b 100644
1346 --- a/fs/xfs/xfs_error.c
1347 +++ b/fs/xfs/xfs_error.c
1348 @@ -167,7 +167,7 @@ xfs_verifier_error(
1349 {
1350 struct xfs_mount *mp = bp->b_target->bt_mount;
1351
1352 - xfs_alert(mp, "Metadata %s detected at %pF, %s block 0x%llx",
1353 + xfs_alert(mp, "Metadata %s detected at %pS, %s block 0x%llx",
1354 bp->b_error == -EFSBADCRC ? "CRC error" : "corruption",
1355 __return_address, bp->b_ops->name, bp->b_bn);
1356
1357 diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
1358 index 586b398f268d..362c6b4c1186 100644
1359 --- a/fs/xfs/xfs_file.c
1360 +++ b/fs/xfs/xfs_file.c
1361 @@ -92,7 +92,7 @@ xfs_zero_range(
1362 xfs_off_t count,
1363 bool *did_zero)
1364 {
1365 - return iomap_zero_range(VFS_I(ip), pos, count, NULL, &xfs_iomap_ops);
1366 + return iomap_zero_range(VFS_I(ip), pos, count, did_zero, &xfs_iomap_ops);
1367 }
1368
1369 int
1370 diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
1371 index 9e795ab08a53..fe9a9a183b2d 100644
1372 --- a/fs/xfs/xfs_inode.c
1373 +++ b/fs/xfs/xfs_inode.c
1374 @@ -1632,10 +1632,12 @@ xfs_itruncate_extents(
1375 goto out;
1376
1377 /*
1378 - * Clear the reflink flag if we truncated everything.
1379 + * Clear the reflink flag if there are no data fork blocks and
1380 + * there are no extents staged in the cow fork.
1381 */
1382 - if (ip->i_d.di_nblocks == 0 && xfs_is_reflink_inode(ip)) {
1383 - ip->i_d.di_flags2 &= ~XFS_DIFLAG2_REFLINK;
1384 + if (xfs_is_reflink_inode(ip) && ip->i_cnextents == 0) {
1385 + if (ip->i_d.di_nblocks == 0)
1386 + ip->i_d.di_flags2 &= ~XFS_DIFLAG2_REFLINK;
1387 xfs_inode_clear_cowblocks_tag(ip);
1388 }
1389
1390 diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c
1391 index 94915747042c..d0a3c4bd2c38 100644
1392 --- a/fs/xfs/xfs_inode_item.c
1393 +++ b/fs/xfs/xfs_inode_item.c
1394 @@ -364,6 +364,9 @@ xfs_inode_to_log_dinode(
1395 to->di_dmstate = from->di_dmstate;
1396 to->di_flags = from->di_flags;
1397
1398 + /* log a dummy value to ensure log structure is fully initialised */
1399 + to->di_next_unlinked = NULLAGINO;
1400 +
1401 if (from->di_version == 3) {
1402 to->di_changecount = inode->i_version;
1403 to->di_crtime.t_sec = from->di_crtime.t_sec;
1404 @@ -404,6 +407,11 @@ xfs_inode_item_format_core(
1405 * the second with the on-disk inode structure, and a possible third and/or
1406 * fourth with the inode data/extents/b-tree root and inode attributes
1407 * data/extents/b-tree root.
1408 + *
1409 + * Note: Always use the 64 bit inode log format structure so we don't
1410 + * leave an uninitialised hole in the format item on 64 bit systems. Log
1411 + * recovery on 32 bit systems handles this just fine, so there's no reason
1412 + * for not using an initialising the properly padded structure all the time.
1413 */
1414 STATIC void
1415 xfs_inode_item_format(
1416 @@ -412,8 +420,8 @@ xfs_inode_item_format(
1417 {
1418 struct xfs_inode_log_item *iip = INODE_ITEM(lip);
1419 struct xfs_inode *ip = iip->ili_inode;
1420 - struct xfs_inode_log_format *ilf;
1421 struct xfs_log_iovec *vecp = NULL;
1422 + struct xfs_inode_log_format *ilf;
1423
1424 ASSERT(ip->i_d.di_version > 1);
1425
1426 @@ -425,7 +433,17 @@ xfs_inode_item_format(
1427 ilf->ilf_boffset = ip->i_imap.im_boffset;
1428 ilf->ilf_fields = XFS_ILOG_CORE;
1429 ilf->ilf_size = 2; /* format + core */
1430 - xlog_finish_iovec(lv, vecp, sizeof(struct xfs_inode_log_format));
1431 +
1432 + /*
1433 + * make sure we don't leak uninitialised data into the log in the case
1434 + * when we don't log every field in the inode.
1435 + */
1436 + ilf->ilf_dsize = 0;
1437 + ilf->ilf_asize = 0;
1438 + ilf->ilf_pad = 0;
1439 + memset(&ilf->ilf_u.ilfu_uuid, 0, sizeof(ilf->ilf_u.ilfu_uuid));
1440 +
1441 + xlog_finish_iovec(lv, vecp, sizeof(*ilf));
1442
1443 xfs_inode_item_format_core(ip, lv, &vecp);
1444 xfs_inode_item_format_data_fork(iip, ilf, lv, &vecp);
1445 @@ -745,7 +763,7 @@ xfs_iflush_done(
1446 */
1447 iip = INODE_ITEM(blip);
1448 if ((iip->ili_logged && blip->li_lsn == iip->ili_flush_lsn) ||
1449 - lip->li_flags & XFS_LI_FAILED)
1450 + (blip->li_flags & XFS_LI_FAILED))
1451 need_ail++;
1452
1453 blip = next;
1454 @@ -855,48 +873,30 @@ xfs_istale_done(
1455 }
1456
1457 /*
1458 - * convert an xfs_inode_log_format struct from either 32 or 64 bit versions
1459 - * (which can have different field alignments) to the native version
1460 + * convert an xfs_inode_log_format struct from the old 32 bit version
1461 + * (which can have different field alignments) to the native 64 bit version
1462 */
1463 int
1464 xfs_inode_item_format_convert(
1465 - xfs_log_iovec_t *buf,
1466 - xfs_inode_log_format_t *in_f)
1467 + struct xfs_log_iovec *buf,
1468 + struct xfs_inode_log_format *in_f)
1469 {
1470 - if (buf->i_len == sizeof(xfs_inode_log_format_32_t)) {
1471 - xfs_inode_log_format_32_t *in_f32 = buf->i_addr;
1472 -
1473 - in_f->ilf_type = in_f32->ilf_type;
1474 - in_f->ilf_size = in_f32->ilf_size;
1475 - in_f->ilf_fields = in_f32->ilf_fields;
1476 - in_f->ilf_asize = in_f32->ilf_asize;
1477 - in_f->ilf_dsize = in_f32->ilf_dsize;
1478 - in_f->ilf_ino = in_f32->ilf_ino;
1479 - /* copy biggest field of ilf_u */
1480 - memcpy(in_f->ilf_u.ilfu_uuid.__u_bits,
1481 - in_f32->ilf_u.ilfu_uuid.__u_bits,
1482 - sizeof(uuid_t));
1483 - in_f->ilf_blkno = in_f32->ilf_blkno;
1484 - in_f->ilf_len = in_f32->ilf_len;
1485 - in_f->ilf_boffset = in_f32->ilf_boffset;
1486 - return 0;
1487 - } else if (buf->i_len == sizeof(xfs_inode_log_format_64_t)){
1488 - xfs_inode_log_format_64_t *in_f64 = buf->i_addr;
1489 -
1490 - in_f->ilf_type = in_f64->ilf_type;
1491 - in_f->ilf_size = in_f64->ilf_size;
1492 - in_f->ilf_fields = in_f64->ilf_fields;
1493 - in_f->ilf_asize = in_f64->ilf_asize;
1494 - in_f->ilf_dsize = in_f64->ilf_dsize;
1495 - in_f->ilf_ino = in_f64->ilf_ino;
1496 - /* copy biggest field of ilf_u */
1497 - memcpy(in_f->ilf_u.ilfu_uuid.__u_bits,
1498 - in_f64->ilf_u.ilfu_uuid.__u_bits,
1499 - sizeof(uuid_t));
1500 - in_f->ilf_blkno = in_f64->ilf_blkno;
1501 - in_f->ilf_len = in_f64->ilf_len;
1502 - in_f->ilf_boffset = in_f64->ilf_boffset;
1503 - return 0;
1504 - }
1505 - return -EFSCORRUPTED;
1506 + struct xfs_inode_log_format_32 *in_f32 = buf->i_addr;
1507 +
1508 + if (buf->i_len != sizeof(*in_f32))
1509 + return -EFSCORRUPTED;
1510 +
1511 + in_f->ilf_type = in_f32->ilf_type;
1512 + in_f->ilf_size = in_f32->ilf_size;
1513 + in_f->ilf_fields = in_f32->ilf_fields;
1514 + in_f->ilf_asize = in_f32->ilf_asize;
1515 + in_f->ilf_dsize = in_f32->ilf_dsize;
1516 + in_f->ilf_ino = in_f32->ilf_ino;
1517 + /* copy biggest field of ilf_u */
1518 + memcpy(in_f->ilf_u.ilfu_uuid.__u_bits,
1519 + in_f32->ilf_u.ilfu_uuid.__u_bits, sizeof(uuid_t));
1520 + in_f->ilf_blkno = in_f32->ilf_blkno;
1521 + in_f->ilf_len = in_f32->ilf_len;
1522 + in_f->ilf_boffset = in_f32->ilf_boffset;
1523 + return 0;
1524 }
1525 diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
1526 index 65740d1cbd92..f286f63c430c 100644
1527 --- a/fs/xfs/xfs_iomap.c
1528 +++ b/fs/xfs/xfs_iomap.c
1529 @@ -836,7 +836,8 @@ int
1530 xfs_iomap_write_unwritten(
1531 xfs_inode_t *ip,
1532 xfs_off_t offset,
1533 - xfs_off_t count)
1534 + xfs_off_t count,
1535 + bool update_isize)
1536 {
1537 xfs_mount_t *mp = ip->i_mount;
1538 xfs_fileoff_t offset_fsb;
1539 @@ -847,6 +848,7 @@ xfs_iomap_write_unwritten(
1540 xfs_trans_t *tp;
1541 xfs_bmbt_irec_t imap;
1542 struct xfs_defer_ops dfops;
1543 + struct inode *inode = VFS_I(ip);
1544 xfs_fsize_t i_size;
1545 uint resblks;
1546 int error;
1547 @@ -906,7 +908,8 @@ xfs_iomap_write_unwritten(
1548 i_size = XFS_FSB_TO_B(mp, offset_fsb + count_fsb);
1549 if (i_size > offset + count)
1550 i_size = offset + count;
1551 -
1552 + if (update_isize && i_size > i_size_read(inode))
1553 + i_size_write(inode, i_size);
1554 i_size = xfs_new_eof(ip, i_size);
1555 if (i_size) {
1556 ip->i_d.di_size = i_size;
1557 diff --git a/fs/xfs/xfs_iomap.h b/fs/xfs/xfs_iomap.h
1558 index 6d45cf01fcff..d71703af5c76 100644
1559 --- a/fs/xfs/xfs_iomap.h
1560 +++ b/fs/xfs/xfs_iomap.h
1561 @@ -27,7 +27,7 @@ int xfs_iomap_write_direct(struct xfs_inode *, xfs_off_t, size_t,
1562 struct xfs_bmbt_irec *, int);
1563 int xfs_iomap_write_allocate(struct xfs_inode *, int, xfs_off_t,
1564 struct xfs_bmbt_irec *);
1565 -int xfs_iomap_write_unwritten(struct xfs_inode *, xfs_off_t, xfs_off_t);
1566 +int xfs_iomap_write_unwritten(struct xfs_inode *, xfs_off_t, xfs_off_t, bool);
1567
1568 void xfs_bmbt_to_iomap(struct xfs_inode *, struct iomap *,
1569 struct xfs_bmbt_irec *);
1570 diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h
1571 index 0c381d71b242..0492436a053f 100644
1572 --- a/fs/xfs/xfs_ondisk.h
1573 +++ b/fs/xfs/xfs_ondisk.h
1574 @@ -134,7 +134,7 @@ xfs_check_ondisk_structs(void)
1575 XFS_CHECK_STRUCT_SIZE(struct xfs_icreate_log, 28);
1576 XFS_CHECK_STRUCT_SIZE(struct xfs_ictimestamp, 8);
1577 XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format_32, 52);
1578 - XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format_64, 56);
1579 + XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format, 56);
1580 XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat, 20);
1581 XFS_CHECK_STRUCT_SIZE(struct xfs_trans_header, 16);
1582 }
1583 diff --git a/fs/xfs/xfs_pnfs.c b/fs/xfs/xfs_pnfs.c
1584 index 93a7aafa56d6..cecd37569ddb 100644
1585 --- a/fs/xfs/xfs_pnfs.c
1586 +++ b/fs/xfs/xfs_pnfs.c
1587 @@ -279,7 +279,7 @@ xfs_fs_commit_blocks(
1588 (end - 1) >> PAGE_SHIFT);
1589 WARN_ON_ONCE(error);
1590
1591 - error = xfs_iomap_write_unwritten(ip, start, length);
1592 + error = xfs_iomap_write_unwritten(ip, start, length, false);
1593 if (error)
1594 goto out_drop_iolock;
1595 }
1596 diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
1597 index 0015c19c7455..17d3c964a2a2 100644
1598 --- a/fs/xfs/xfs_reflink.c
1599 +++ b/fs/xfs/xfs_reflink.c
1600 @@ -767,7 +767,13 @@ xfs_reflink_end_cow(
1601
1602 /* If there is a hole at end_fsb - 1 go to the previous extent */
1603 if (eof || got.br_startoff > end_fsb) {
1604 - ASSERT(idx > 0);
1605 + /*
1606 + * In case of racing, overlapping AIO writes no COW extents
1607 + * might be left by the time I/O completes for the loser of
1608 + * the race. In that case we are done.
1609 + */
1610 + if (idx <= 0)
1611 + goto out_cancel;
1612 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, --idx), &got);
1613 }
1614
1615 @@ -841,6 +847,7 @@ xfs_reflink_end_cow(
1616
1617 out_defer:
1618 xfs_defer_cancel(&dfops);
1619 +out_cancel:
1620 xfs_trans_cancel(tp);
1621 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1622 out:
1623 diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
1624 index d596a076da11..8cc99de27bc2 100644
1625 --- a/include/linux/hyperv.h
1626 +++ b/include/linux/hyperv.h
1627 @@ -1521,11 +1521,11 @@ static inline void hv_signal_on_read(struct vmbus_channel *channel)
1628
1629 cur_write_sz = hv_get_bytes_to_write(rbi);
1630
1631 - if (cur_write_sz < pending_sz)
1632 + if (cur_write_sz <= pending_sz)
1633 return;
1634
1635 cached_write_sz = hv_get_cached_bytes_to_write(rbi);
1636 - if (cached_write_sz < pending_sz)
1637 + if (cached_write_sz <= pending_sz)
1638 vmbus_setevent(channel);
1639
1640 return;
1641 diff --git a/include/linux/key.h b/include/linux/key.h
1642 index 6a544726903e..ed9b44fd9580 100644
1643 --- a/include/linux/key.h
1644 +++ b/include/linux/key.h
1645 @@ -126,6 +126,11 @@ static inline bool is_key_possessed(const key_ref_t key_ref)
1646 return (unsigned long) key_ref & 1UL;
1647 }
1648
1649 +enum key_state {
1650 + KEY_IS_UNINSTANTIATED,
1651 + KEY_IS_POSITIVE, /* Positively instantiated */
1652 +};
1653 +
1654 /*****************************************************************************/
1655 /*
1656 * authentication token / access credential / keyring
1657 @@ -157,6 +162,7 @@ struct key {
1658 * - may not match RCU dereferenced payload
1659 * - payload should contain own length
1660 */
1661 + short state; /* Key state (+) or rejection error (-) */
1662
1663 #ifdef KEY_DEBUGGING
1664 unsigned magic;
1665 @@ -165,18 +171,16 @@ struct key {
1666 #endif
1667
1668 unsigned long flags; /* status flags (change with bitops) */
1669 -#define KEY_FLAG_INSTANTIATED 0 /* set if key has been instantiated */
1670 -#define KEY_FLAG_DEAD 1 /* set if key type has been deleted */
1671 -#define KEY_FLAG_REVOKED 2 /* set if key had been revoked */
1672 -#define KEY_FLAG_IN_QUOTA 3 /* set if key consumes quota */
1673 -#define KEY_FLAG_USER_CONSTRUCT 4 /* set if key is being constructed in userspace */
1674 -#define KEY_FLAG_NEGATIVE 5 /* set if key is negative */
1675 -#define KEY_FLAG_ROOT_CAN_CLEAR 6 /* set if key can be cleared by root without permission */
1676 -#define KEY_FLAG_INVALIDATED 7 /* set if key has been invalidated */
1677 -#define KEY_FLAG_BUILTIN 8 /* set if key is built in to the kernel */
1678 -#define KEY_FLAG_ROOT_CAN_INVAL 9 /* set if key can be invalidated by root without permission */
1679 -#define KEY_FLAG_KEEP 10 /* set if key should not be removed */
1680 -#define KEY_FLAG_UID_KEYRING 11 /* set if key is a user or user session keyring */
1681 +#define KEY_FLAG_DEAD 0 /* set if key type has been deleted */
1682 +#define KEY_FLAG_REVOKED 1 /* set if key had been revoked */
1683 +#define KEY_FLAG_IN_QUOTA 2 /* set if key consumes quota */
1684 +#define KEY_FLAG_USER_CONSTRUCT 3 /* set if key is being constructed in userspace */
1685 +#define KEY_FLAG_ROOT_CAN_CLEAR 4 /* set if key can be cleared by root without permission */
1686 +#define KEY_FLAG_INVALIDATED 5 /* set if key has been invalidated */
1687 +#define KEY_FLAG_BUILTIN 6 /* set if key is built in to the kernel */
1688 +#define KEY_FLAG_ROOT_CAN_INVAL 7 /* set if key can be invalidated by root without permission */
1689 +#define KEY_FLAG_KEEP 8 /* set if key should not be removed */
1690 +#define KEY_FLAG_UID_KEYRING 9 /* set if key is a user or user session keyring */
1691
1692 /* the key type and key description string
1693 * - the desc is used to match a key against search criteria
1694 @@ -202,7 +206,6 @@ struct key {
1695 struct list_head name_link;
1696 struct assoc_array keys;
1697 };
1698 - int reject_error;
1699 };
1700
1701 /* This is set on a keyring to restrict the addition of a link to a key
1702 @@ -343,17 +346,27 @@ extern void key_set_timeout(struct key *, unsigned);
1703 #define KEY_NEED_SETATTR 0x20 /* Require permission to change attributes */
1704 #define KEY_NEED_ALL 0x3f /* All the above permissions */
1705
1706 +static inline short key_read_state(const struct key *key)
1707 +{
1708 + /* Barrier versus mark_key_instantiated(). */
1709 + return smp_load_acquire(&key->state);
1710 +}
1711 +
1712 /**
1713 - * key_is_instantiated - Determine if a key has been positively instantiated
1714 + * key_is_positive - Determine if a key has been positively instantiated
1715 * @key: The key to check.
1716 *
1717 * Return true if the specified key has been positively instantiated, false
1718 * otherwise.
1719 */
1720 -static inline bool key_is_instantiated(const struct key *key)
1721 +static inline bool key_is_positive(const struct key *key)
1722 +{
1723 + return key_read_state(key) == KEY_IS_POSITIVE;
1724 +}
1725 +
1726 +static inline bool key_is_negative(const struct key *key)
1727 {
1728 - return test_bit(KEY_FLAG_INSTANTIATED, &key->flags) &&
1729 - !test_bit(KEY_FLAG_NEGATIVE, &key->flags);
1730 + return key_read_state(key) < 0;
1731 }
1732
1733 #define rcu_dereference_key(KEY) \
1734 diff --git a/include/linux/mbus.h b/include/linux/mbus.h
1735 index 2931aa43dab1..f70420e65ad7 100644
1736 --- a/include/linux/mbus.h
1737 +++ b/include/linux/mbus.h
1738 @@ -31,8 +31,8 @@ struct mbus_dram_target_info
1739 struct mbus_dram_window {
1740 u8 cs_index;
1741 u8 mbus_attr;
1742 - u32 base;
1743 - u32 size;
1744 + u64 base;
1745 + u64 size;
1746 } cs[4];
1747 };
1748
1749 diff --git a/lib/digsig.c b/lib/digsig.c
1750 index 55b8b2f41a9e..a876156503f0 100644
1751 --- a/lib/digsig.c
1752 +++ b/lib/digsig.c
1753 @@ -87,6 +87,12 @@ static int digsig_verify_rsa(struct key *key,
1754 down_read(&key->sem);
1755 ukp = user_key_payload(key);
1756
1757 + if (!ukp) {
1758 + /* key was revoked before we acquired its semaphore */
1759 + err = -EKEYREVOKED;
1760 + goto err1;
1761 + }
1762 +
1763 if (ukp->datalen < sizeof(*pkh))
1764 goto err1;
1765
1766 diff --git a/net/dns_resolver/dns_key.c b/net/dns_resolver/dns_key.c
1767 index 8737412c7b27..e1d4d898a007 100644
1768 --- a/net/dns_resolver/dns_key.c
1769 +++ b/net/dns_resolver/dns_key.c
1770 @@ -224,7 +224,7 @@ static int dns_resolver_match_preparse(struct key_match_data *match_data)
1771 static void dns_resolver_describe(const struct key *key, struct seq_file *m)
1772 {
1773 seq_puts(m, key->description);
1774 - if (key_is_instantiated(key)) {
1775 + if (key_is_positive(key)) {
1776 int err = PTR_ERR(key->payload.data[dns_key_error]);
1777
1778 if (err)
1779 diff --git a/security/keys/big_key.c b/security/keys/big_key.c
1780 index 47c6dcab1a8e..e6288173d99d 100644
1781 --- a/security/keys/big_key.c
1782 +++ b/security/keys/big_key.c
1783 @@ -245,7 +245,7 @@ void big_key_revoke(struct key *key)
1784
1785 /* clear the quota */
1786 key_payload_reserve(key, 0);
1787 - if (key_is_instantiated(key) &&
1788 + if (key_is_positive(key) &&
1789 (size_t)key->payload.data[big_key_len] > BIG_KEY_FILE_THRESHOLD)
1790 vfs_truncate(path, 0);
1791 }
1792 @@ -277,7 +277,7 @@ void big_key_describe(const struct key *key, struct seq_file *m)
1793
1794 seq_puts(m, key->description);
1795
1796 - if (key_is_instantiated(key))
1797 + if (key_is_positive(key))
1798 seq_printf(m, ": %zu [%s]",
1799 datalen,
1800 datalen > BIG_KEY_FILE_THRESHOLD ? "file" : "buff");
1801 diff --git a/security/keys/encrypted-keys/encrypted.c b/security/keys/encrypted-keys/encrypted.c
1802 index 8d9330aba77e..a871159bf03c 100644
1803 --- a/security/keys/encrypted-keys/encrypted.c
1804 +++ b/security/keys/encrypted-keys/encrypted.c
1805 @@ -315,6 +315,13 @@ static struct key *request_user_key(const char *master_desc, const u8 **master_k
1806
1807 down_read(&ukey->sem);
1808 upayload = user_key_payload(ukey);
1809 + if (!upayload) {
1810 + /* key was revoked before we acquired its semaphore */
1811 + up_read(&ukey->sem);
1812 + key_put(ukey);
1813 + ukey = ERR_PTR(-EKEYREVOKED);
1814 + goto error;
1815 + }
1816 *master_key = upayload->data;
1817 *master_keylen = upayload->datalen;
1818 error:
1819 @@ -867,7 +874,7 @@ static int encrypted_update(struct key *key, struct key_preparsed_payload *prep)
1820 size_t datalen = prep->datalen;
1821 int ret = 0;
1822
1823 - if (test_bit(KEY_FLAG_NEGATIVE, &key->flags))
1824 + if (key_is_negative(key))
1825 return -ENOKEY;
1826 if (datalen <= 0 || datalen > 32767 || !prep->data)
1827 return -EINVAL;
1828 diff --git a/security/keys/gc.c b/security/keys/gc.c
1829 index 9cb4fe4478a1..1659094d684d 100644
1830 --- a/security/keys/gc.c
1831 +++ b/security/keys/gc.c
1832 @@ -129,15 +129,15 @@ static noinline void key_gc_unused_keys(struct list_head *keys)
1833 while (!list_empty(keys)) {
1834 struct key *key =
1835 list_entry(keys->next, struct key, graveyard_link);
1836 + short state = key->state;
1837 +
1838 list_del(&key->graveyard_link);
1839
1840 kdebug("- %u", key->serial);
1841 key_check(key);
1842
1843 /* Throw away the key data if the key is instantiated */
1844 - if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags) &&
1845 - !test_bit(KEY_FLAG_NEGATIVE, &key->flags) &&
1846 - key->type->destroy)
1847 + if (state == KEY_IS_POSITIVE && key->type->destroy)
1848 key->type->destroy(key);
1849
1850 security_key_free(key);
1851 @@ -151,7 +151,7 @@ static noinline void key_gc_unused_keys(struct list_head *keys)
1852 }
1853
1854 atomic_dec(&key->user->nkeys);
1855 - if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags))
1856 + if (state != KEY_IS_UNINSTANTIATED)
1857 atomic_dec(&key->user->nikeys);
1858
1859 key_user_put(key->user);
1860 diff --git a/security/keys/key.c b/security/keys/key.c
1861 index 135e1eb7e468..7dc59069e8c7 100644
1862 --- a/security/keys/key.c
1863 +++ b/security/keys/key.c
1864 @@ -400,6 +400,18 @@ int key_payload_reserve(struct key *key, size_t datalen)
1865 }
1866 EXPORT_SYMBOL(key_payload_reserve);
1867
1868 +/*
1869 + * Change the key state to being instantiated.
1870 + */
1871 +static void mark_key_instantiated(struct key *key, int reject_error)
1872 +{
1873 + /* Commit the payload before setting the state; barrier versus
1874 + * key_read_state().
1875 + */
1876 + smp_store_release(&key->state,
1877 + (reject_error < 0) ? reject_error : KEY_IS_POSITIVE);
1878 +}
1879 +
1880 /*
1881 * Instantiate a key and link it into the target keyring atomically. Must be
1882 * called with the target keyring's semaphore writelocked. The target key's
1883 @@ -423,14 +435,14 @@ static int __key_instantiate_and_link(struct key *key,
1884 mutex_lock(&key_construction_mutex);
1885
1886 /* can't instantiate twice */
1887 - if (!test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) {
1888 + if (key->state == KEY_IS_UNINSTANTIATED) {
1889 /* instantiate the key */
1890 ret = key->type->instantiate(key, prep);
1891
1892 if (ret == 0) {
1893 /* mark the key as being instantiated */
1894 atomic_inc(&key->user->nikeys);
1895 - set_bit(KEY_FLAG_INSTANTIATED, &key->flags);
1896 + mark_key_instantiated(key, 0);
1897
1898 if (test_and_clear_bit(KEY_FLAG_USER_CONSTRUCT, &key->flags))
1899 awaken = 1;
1900 @@ -572,13 +584,10 @@ int key_reject_and_link(struct key *key,
1901 mutex_lock(&key_construction_mutex);
1902
1903 /* can't instantiate twice */
1904 - if (!test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) {
1905 + if (key->state == KEY_IS_UNINSTANTIATED) {
1906 /* mark the key as being negatively instantiated */
1907 atomic_inc(&key->user->nikeys);
1908 - key->reject_error = -error;
1909 - smp_wmb();
1910 - set_bit(KEY_FLAG_NEGATIVE, &key->flags);
1911 - set_bit(KEY_FLAG_INSTANTIATED, &key->flags);
1912 + mark_key_instantiated(key, -error);
1913 now = current_kernel_time();
1914 key->expiry = now.tv_sec + timeout;
1915 key_schedule_gc(key->expiry + key_gc_delay);
1916 @@ -750,8 +759,8 @@ static inline key_ref_t __key_update(key_ref_t key_ref,
1917
1918 ret = key->type->update(key, prep);
1919 if (ret == 0)
1920 - /* updating a negative key instantiates it */
1921 - clear_bit(KEY_FLAG_NEGATIVE, &key->flags);
1922 + /* Updating a negative key positively instantiates it */
1923 + mark_key_instantiated(key, 0);
1924
1925 up_write(&key->sem);
1926
1927 @@ -935,6 +944,16 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
1928 */
1929 __key_link_end(keyring, &index_key, edit);
1930
1931 + key = key_ref_to_ptr(key_ref);
1932 + if (test_bit(KEY_FLAG_USER_CONSTRUCT, &key->flags)) {
1933 + ret = wait_for_key_construction(key, true);
1934 + if (ret < 0) {
1935 + key_ref_put(key_ref);
1936 + key_ref = ERR_PTR(ret);
1937 + goto error_free_prep;
1938 + }
1939 + }
1940 +
1941 key_ref = __key_update(key_ref, &prep);
1942 goto error_free_prep;
1943 }
1944 @@ -985,8 +1004,8 @@ int key_update(key_ref_t key_ref, const void *payload, size_t plen)
1945
1946 ret = key->type->update(key, &prep);
1947 if (ret == 0)
1948 - /* updating a negative key instantiates it */
1949 - clear_bit(KEY_FLAG_NEGATIVE, &key->flags);
1950 + /* Updating a negative key positively instantiates it */
1951 + mark_key_instantiated(key, 0);
1952
1953 up_write(&key->sem);
1954
1955 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
1956 index 1302cb398346..797edcf1d424 100644
1957 --- a/security/keys/keyctl.c
1958 +++ b/security/keys/keyctl.c
1959 @@ -766,10 +766,9 @@ long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
1960
1961 key = key_ref_to_ptr(key_ref);
1962
1963 - if (test_bit(KEY_FLAG_NEGATIVE, &key->flags)) {
1964 - ret = -ENOKEY;
1965 - goto error2;
1966 - }
1967 + ret = key_read_state(key);
1968 + if (ret < 0)
1969 + goto error2; /* Negatively instantiated */
1970
1971 /* see if we can read it directly */
1972 ret = key_permission(key_ref, KEY_NEED_READ);
1973 @@ -901,7 +900,7 @@ long keyctl_chown_key(key_serial_t id, uid_t user, gid_t group)
1974 atomic_dec(&key->user->nkeys);
1975 atomic_inc(&newowner->nkeys);
1976
1977 - if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) {
1978 + if (key->state != KEY_IS_UNINSTANTIATED) {
1979 atomic_dec(&key->user->nikeys);
1980 atomic_inc(&newowner->nikeys);
1981 }
1982 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
1983 index a86d0ae1773c..32969f630438 100644
1984 --- a/security/keys/keyring.c
1985 +++ b/security/keys/keyring.c
1986 @@ -407,7 +407,7 @@ static void keyring_describe(const struct key *keyring, struct seq_file *m)
1987 else
1988 seq_puts(m, "[anon]");
1989
1990 - if (key_is_instantiated(keyring)) {
1991 + if (key_is_positive(keyring)) {
1992 if (keyring->keys.nr_leaves_on_tree != 0)
1993 seq_printf(m, ": %lu", keyring->keys.nr_leaves_on_tree);
1994 else
1995 @@ -546,7 +546,8 @@ static int keyring_search_iterator(const void *object, void *iterator_data)
1996 {
1997 struct keyring_search_context *ctx = iterator_data;
1998 const struct key *key = keyring_ptr_to_key(object);
1999 - unsigned long kflags = key->flags;
2000 + unsigned long kflags = READ_ONCE(key->flags);
2001 + short state = READ_ONCE(key->state);
2002
2003 kenter("{%d}", key->serial);
2004
2005 @@ -590,9 +591,8 @@ static int keyring_search_iterator(const void *object, void *iterator_data)
2006
2007 if (ctx->flags & KEYRING_SEARCH_DO_STATE_CHECK) {
2008 /* we set a different error code if we pass a negative key */
2009 - if (kflags & (1 << KEY_FLAG_NEGATIVE)) {
2010 - smp_rmb();
2011 - ctx->result = ERR_PTR(key->reject_error);
2012 + if (state < 0) {
2013 + ctx->result = ERR_PTR(state);
2014 kleave(" = %d [neg]", ctx->skipped_ret);
2015 goto skipped;
2016 }
2017 diff --git a/security/keys/proc.c b/security/keys/proc.c
2018 index b9f531c9e4fa..036128682463 100644
2019 --- a/security/keys/proc.c
2020 +++ b/security/keys/proc.c
2021 @@ -182,6 +182,7 @@ static int proc_keys_show(struct seq_file *m, void *v)
2022 unsigned long timo;
2023 key_ref_t key_ref, skey_ref;
2024 char xbuf[16];
2025 + short state;
2026 int rc;
2027
2028 struct keyring_search_context ctx = {
2029 @@ -240,17 +241,19 @@ static int proc_keys_show(struct seq_file *m, void *v)
2030 sprintf(xbuf, "%luw", timo / (60*60*24*7));
2031 }
2032
2033 + state = key_read_state(key);
2034 +
2035 #define showflag(KEY, LETTER, FLAG) \
2036 (test_bit(FLAG, &(KEY)->flags) ? LETTER : '-')
2037
2038 seq_printf(m, "%08x %c%c%c%c%c%c%c %5d %4s %08x %5d %5d %-9.9s ",
2039 key->serial,
2040 - showflag(key, 'I', KEY_FLAG_INSTANTIATED),
2041 + state != KEY_IS_UNINSTANTIATED ? 'I' : '-',
2042 showflag(key, 'R', KEY_FLAG_REVOKED),
2043 showflag(key, 'D', KEY_FLAG_DEAD),
2044 showflag(key, 'Q', KEY_FLAG_IN_QUOTA),
2045 showflag(key, 'U', KEY_FLAG_USER_CONSTRUCT),
2046 - showflag(key, 'N', KEY_FLAG_NEGATIVE),
2047 + state < 0 ? 'N' : '-',
2048 showflag(key, 'i', KEY_FLAG_INVALIDATED),
2049 atomic_read(&key->usage),
2050 xbuf,
2051 diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
2052 index ce45c78cf0a2..2d35d71d7d9a 100644
2053 --- a/security/keys/process_keys.c
2054 +++ b/security/keys/process_keys.c
2055 @@ -729,7 +729,7 @@ key_ref_t lookup_user_key(key_serial_t id, unsigned long lflags,
2056
2057 ret = -EIO;
2058 if (!(lflags & KEY_LOOKUP_PARTIAL) &&
2059 - !test_bit(KEY_FLAG_INSTANTIATED, &key->flags))
2060 + key_read_state(key) == KEY_IS_UNINSTANTIATED)
2061 goto invalid_key;
2062
2063 /* check the permissions */
2064 diff --git a/security/keys/request_key.c b/security/keys/request_key.c
2065 index 43affcf10b22..5030fcf23681 100644
2066 --- a/security/keys/request_key.c
2067 +++ b/security/keys/request_key.c
2068 @@ -594,10 +594,9 @@ int wait_for_key_construction(struct key *key, bool intr)
2069 intr ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
2070 if (ret)
2071 return -ERESTARTSYS;
2072 - if (test_bit(KEY_FLAG_NEGATIVE, &key->flags)) {
2073 - smp_rmb();
2074 - return key->reject_error;
2075 - }
2076 + ret = key_read_state(key);
2077 + if (ret < 0)
2078 + return ret;
2079 return key_validate(key);
2080 }
2081 EXPORT_SYMBOL(wait_for_key_construction);
2082 diff --git a/security/keys/request_key_auth.c b/security/keys/request_key_auth.c
2083 index 9db8b4a82787..ba74a0b4d1cb 100644
2084 --- a/security/keys/request_key_auth.c
2085 +++ b/security/keys/request_key_auth.c
2086 @@ -73,7 +73,7 @@ static void request_key_auth_describe(const struct key *key,
2087
2088 seq_puts(m, "key:");
2089 seq_puts(m, key->description);
2090 - if (key_is_instantiated(key))
2091 + if (key_is_positive(key))
2092 seq_printf(m, " pid:%d ci:%zu", rka->pid, rka->callout_len);
2093 }
2094
2095 diff --git a/security/keys/trusted.c b/security/keys/trusted.c
2096 index 90d61751ff12..f4db42e669e9 100644
2097 --- a/security/keys/trusted.c
2098 +++ b/security/keys/trusted.c
2099 @@ -1067,7 +1067,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep)
2100 char *datablob;
2101 int ret = 0;
2102
2103 - if (test_bit(KEY_FLAG_NEGATIVE, &key->flags))
2104 + if (key_is_negative(key))
2105 return -ENOKEY;
2106 p = key->payload.data[0];
2107 if (!p->migratable)
2108 diff --git a/security/keys/user_defined.c b/security/keys/user_defined.c
2109 index 66b1840b4110..3dc2607211cc 100644
2110 --- a/security/keys/user_defined.c
2111 +++ b/security/keys/user_defined.c
2112 @@ -106,7 +106,7 @@ int user_update(struct key *key, struct key_preparsed_payload *prep)
2113
2114 /* attach the new data, displacing the old */
2115 key->expiry = prep->expiry;
2116 - if (!test_bit(KEY_FLAG_NEGATIVE, &key->flags))
2117 + if (key_is_positive(key))
2118 zap = rcu_dereference_key(key);
2119 rcu_assign_keypointer(key, prep->payload.data[0]);
2120 prep->payload.data[0] = NULL;
2121 @@ -154,7 +154,7 @@ EXPORT_SYMBOL_GPL(user_destroy);
2122 void user_describe(const struct key *key, struct seq_file *m)
2123 {
2124 seq_puts(m, key->description);
2125 - if (key_is_instantiated(key))
2126 + if (key_is_positive(key))
2127 seq_printf(m, ": %u", key->datalen);
2128 }
2129
2130 diff --git a/sound/core/seq/seq_lock.c b/sound/core/seq/seq_lock.c
2131 index 12ba83367b1b..ba5752ee9af3 100644
2132 --- a/sound/core/seq/seq_lock.c
2133 +++ b/sound/core/seq/seq_lock.c
2134 @@ -23,8 +23,6 @@
2135 #include <sound/core.h>
2136 #include "seq_lock.h"
2137
2138 -#if defined(CONFIG_SMP) || defined(CONFIG_SND_DEBUG)
2139 -
2140 /* wait until all locks are released */
2141 void snd_use_lock_sync_helper(snd_use_lock_t *lockp, const char *file, int line)
2142 {
2143 @@ -42,5 +40,3 @@ void snd_use_lock_sync_helper(snd_use_lock_t *lockp, const char *file, int line)
2144 }
2145
2146 EXPORT_SYMBOL(snd_use_lock_sync_helper);
2147 -
2148 -#endif
2149 diff --git a/sound/core/seq/seq_lock.h b/sound/core/seq/seq_lock.h
2150 index 54044bc2c9ef..ac38031c370e 100644
2151 --- a/sound/core/seq/seq_lock.h
2152 +++ b/sound/core/seq/seq_lock.h
2153 @@ -3,8 +3,6 @@
2154
2155 #include <linux/sched.h>
2156
2157 -#if defined(CONFIG_SMP) || defined(CONFIG_SND_DEBUG)
2158 -
2159 typedef atomic_t snd_use_lock_t;
2160
2161 /* initialize lock */
2162 @@ -20,14 +18,4 @@ typedef atomic_t snd_use_lock_t;
2163 void snd_use_lock_sync_helper(snd_use_lock_t *lock, const char *file, int line);
2164 #define snd_use_lock_sync(lockp) snd_use_lock_sync_helper(lockp, __BASE_FILE__, __LINE__)
2165
2166 -#else /* SMP || CONFIG_SND_DEBUG */
2167 -
2168 -typedef spinlock_t snd_use_lock_t; /* dummy */
2169 -#define snd_use_lock_init(lockp) /**/
2170 -#define snd_use_lock_use(lockp) /**/
2171 -#define snd_use_lock_free(lockp) /**/
2172 -#define snd_use_lock_sync(lockp) /**/
2173 -
2174 -#endif /* SMP || CONFIG_SND_DEBUG */
2175 -
2176 #endif /* __SND_SEQ_LOCK_H */
2177 diff --git a/sound/hda/hdac_controller.c b/sound/hda/hdac_controller.c
2178 index 0f41257d339e..8761877207ec 100644
2179 --- a/sound/hda/hdac_controller.c
2180 +++ b/sound/hda/hdac_controller.c
2181 @@ -284,6 +284,11 @@ int snd_hdac_bus_parse_capabilities(struct hdac_bus *bus)
2182 dev_dbg(bus->dev, "HDA capability ID: 0x%x\n",
2183 (cur_cap & AZX_CAP_HDR_ID_MASK) >> AZX_CAP_HDR_ID_OFF);
2184
2185 + if (cur_cap == -1) {
2186 + dev_dbg(bus->dev, "Invalid capability reg read\n");
2187 + break;
2188 + }
2189 +
2190 switch ((cur_cap & AZX_CAP_HDR_ID_MASK) >> AZX_CAP_HDR_ID_OFF) {
2191 case AZX_ML_CAP_ID:
2192 dev_dbg(bus->dev, "Found ML capability\n");
2193 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
2194 index 9913be8532ab..e46c561a8c90 100644
2195 --- a/sound/pci/hda/hda_codec.c
2196 +++ b/sound/pci/hda/hda_codec.c
2197 @@ -1755,7 +1755,7 @@ static int get_kctl_0dB_offset(struct hda_codec *codec,
2198 return -1;
2199 if (*step_to_check && *step_to_check != step) {
2200 codec_err(codec, "Mismatching dB step for vmaster slave (%d!=%d)\n",
2201 -- *step_to_check, step);
2202 + *step_to_check, step);
2203 return -1;
2204 }
2205 *step_to_check = step;
2206 diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
2207 index 286efc3a6116..7613b9e07b5c 100644
2208 --- a/sound/usb/quirks.c
2209 +++ b/sound/usb/quirks.c
2210 @@ -1352,6 +1352,7 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
2211 case USB_ID(0x20b1, 0x2008): /* Matrix Audio X-Sabre */
2212 case USB_ID(0x20b1, 0x300a): /* Matrix Audio Mini-i Pro */
2213 case USB_ID(0x22d9, 0x0416): /* OPPO HA-1 */
2214 + case USB_ID(0x2772, 0x0230): /* Pro-Ject Pre Box S2 Digital */
2215 if (fp->altsetting == 2)
2216 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
2217 break;