| @@ -3466,7 +3466,31 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, · 3465 unmodified lines |
| 3466 | 3466 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
| 3467 | 3467 | int *ent_cpu, u64 *ent_ts) |
| 3468 | 3468 | { |
| 3469 | | − return __find_next_entry(iter, ent_cpu, NULL, ent_ts); |
| 3469 | + /* __find_next_entry will reset ent_size */ |
| 3470 | + int ent_size = iter->ent_size; |
| 3471 | + struct trace_entry *entry; |
| 3472 | + |
| 3473 | + /* |
| 3474 | + * The __find_next_entry() may call peek_next_entry(), which may |
| 3475 | + * call ring_buffer_peek() that may make the contents of iter->ent |
| 3476 | + * undefined. Need to copy iter->ent now. |
| 3477 | + */ |
| 3478 | + if (iter->ent && iter->ent != iter->temp) { |
| 3479 | + if (!iter->temp || iter->temp_size < iter->ent_size) { |
| 3480 | + kfree(iter->temp); |
| 3481 | + iter->temp = kmalloc(iter->ent_size, GFP_KERNEL); |
| 3482 | + if (!iter->temp) |
| 3483 | + return NULL; |
| 3484 | + } |
| 3485 | + memcpy(iter->temp, iter->ent, iter->ent_size); |
| 3486 | + iter->temp_size = iter->ent_size; |
| 3487 | + iter->ent = iter->temp; |
| 3488 | + } |
| 3489 | + entry = __find_next_entry(iter, ent_cpu, NULL, ent_ts); |
| 3490 | + /* Put back the original ent_size */ |
| 3491 | + iter->ent_size = ent_size; |
| 3492 | + |
| 3493 | + return entry; |
| 3470 | 3494 | } |
| 3471 | 3495 | |
| 3472 | 3496 | /* Find the next real entry, and increment the iterator to the next entry */ |
| @@ -4197,6 +4221,18 @@ __tracing_open(struct inode *inode, struct file *file, bool snapshot) · 724 unmodified lines |
| 4197 | 4221 | if (!iter->buffer_iter) |
| 4198 | 4222 | goto release; |
| 4199 | 4223 | |
| 4224 | + /* |
| 4225 | + * trace_find_next_entry() may need to save off iter->ent. |
| 4226 | + * It will place it into the iter->temp buffer. As most |
| 4227 | + * events are less than 128, allocate a buffer of that size. |
| 4228 | + * If one is greater, then trace_find_next_entry() will |
| 4229 | + * allocate a new buffer to adjust for the bigger iter->ent. |
| 4230 | + * It's not critical if it fails to get allocated here. |
| 4231 | + */ |
| 4232 | + iter->temp = kmalloc(128, GFP_KERNEL); |
| 4233 | + if (iter->temp) |
| 4234 | + iter->temp_size = 128; |
| 4235 | + |
| 4200 | 4236 | /* |
| 4201 | 4237 | * We make a copy of the current tracer to avoid concurrent |
| 4202 | 4238 | * changes on it while we are reading. |
| @@ -4269,6 +4305,7 @@ __tracing_open(struct inode *inode, struct file *file, bool snapshot) · 66 unmodified lines |
| 4269 | 4305 | fail: |
| 4270 | 4306 | mutex_unlock(&trace_types_lock); |
| 4271 | 4307 | kfree(iter->trace); |
| 4308 | + kfree(iter->temp); |
| 4272 | 4309 | kfree(iter->buffer_iter); |
| 4273 | 4310 | release: |
| 4274 | 4311 | seq_release_private(inode, file); |
| @@ -4344,6 +4381,7 @@ static int tracing_release(struct inode *inode, struct file *file) · 69 unmodified lines |
| 4344 | 4381 | |
| 4345 | 4382 | mutex_destroy(&iter->mutex); |
| 4346 | 4383 | free_cpumask_var(iter->started); |
| 4384 | + kfree(iter->temp); |
| 4347 | 4385 | kfree(iter->trace); |
| 4348 | 4386 | kfree(iter->buffer_iter); |
| 4349 | 4387 | seq_release_private(inode, file); |