o Following patch provides purely cosmetic changes and corrects CodingStyle guide lines related certain issues like below in kexec related files o braces for one line "if" statements, "for" loops, o more than 80 column wide lines, o No space after "while", "for" and "switch" key words o Changes: o take-2: Removed the extra tab before "case" key words. o take-3: Put operator at the end of line and space before "*/"
Showing the changes to kernel (1 of 10 files). Show all
Unified · Split
| @@ -87,12 +87,15 @@ int kexec_should_crash(struct task_struct *p) · 86 unmodified lines | ||
| 87 | 87 | */ |
| 88 | 88 | #define KIMAGE_NO_DEST (-1UL) |
| 89 | 89 | |
| 90 | −static int kimage_is_destination_range( | |
| 91 | − struct kimage *image, unsigned long start, unsigned long end); | |
| 92 | −static struct page *kimage_alloc_page(struct kimage *image, unsigned int gfp_mask, unsigned long dest); | |
| 90 | +static int kimage_is_destination_range(struct kimage *image, | |
| 91 | + unsigned long start, unsigned long end); | |
| 92 | +static struct page *kimage_alloc_page(struct kimage *image, | |
| 93 | + unsigned int gfp_mask, | |
| 94 | + unsigned long dest); | |
| 93 | 95 | |
| 94 | 96 | static int do_kimage_alloc(struct kimage **rimage, unsigned long entry, |
| 95 | − unsigned long nr_segments, struct kexec_segment __user *segments) | |
| 97 | + unsigned long nr_segments, | |
| 98 | + struct kexec_segment __user *segments) | |
| 96 | 99 | { |
| 97 | 100 | size_t segment_bytes; |
| 98 | 101 | struct kimage *image; |
| @@ -102,9 +105,9 @@ static int do_kimage_alloc(struct kimage **rimage, unsigned long entry, · 3 unmodified lines | ||
| 102 | 105 | /* Allocate a controlling structure */ |
| 103 | 106 | result = -ENOMEM; |
| 104 | 107 | image = kmalloc(sizeof(*image), GFP_KERNEL); |
| 105 | − if (!image) { | |
| 108 | + if (!image) | |
| 106 | 109 | goto out; |
| 107 | − } | |
| 110 | + | |
| 108 | 111 | memset(image, 0, sizeof(*image)); |
| 109 | 112 | image->head = 0; |
| 110 | 113 | image->entry = &image->head; |
| @@ -145,6 +148,7 @@ static int do_kimage_alloc(struct kimage **rimage, unsigned long entry, · 34 unmodified lines | ||
| 145 | 148 | result = -EADDRNOTAVAIL; |
| 146 | 149 | for (i = 0; i < nr_segments; i++) { |
| 147 | 150 | unsigned long mstart, mend; |
| 151 | + | |
| 148 | 152 | mstart = image->segment[i].mem; |
| 149 | 153 | mend = mstart + image->segment[i].memsz; |
| 150 | 154 | if ((mstart & ~PAGE_MASK) || (mend & ~PAGE_MASK)) |
| @@ -159,12 +163,13 @@ static int do_kimage_alloc(struct kimage **rimage, unsigned long entry, · 8 unmodified lines | ||
| 159 | 163 | * easy explanation as one segment stops on another. |
| 160 | 164 | */ |
| 161 | 165 | result = -EINVAL; |
| 162 | − for(i = 0; i < nr_segments; i++) { | |
| 166 | + for (i = 0; i < nr_segments; i++) { | |
| 163 | 167 | unsigned long mstart, mend; |
| 164 | 168 | unsigned long j; |
| 169 | + | |
| 165 | 170 | mstart = image->segment[i].mem; |
| 166 | 171 | mend = mstart + image->segment[i].memsz; |
| 167 | − for(j = 0; j < i; j++) { | |
| 172 | + for (j = 0; j < i; j++) { | |
| 168 | 173 | unsigned long pstart, pend; |
| 169 | 174 | pstart = image->segment[j].mem; |
| 170 | 175 | pend = pstart + image->segment[j].memsz; |
| @@ -180,25 +185,25 @@ static int do_kimage_alloc(struct kimage **rimage, unsigned long entry, · 9 unmodified lines | ||
| 180 | 185 | * later on. |
| 181 | 186 | */ |
| 182 | 187 | result = -EINVAL; |
| 183 | − for(i = 0; i < nr_segments; i++) { | |
| 188 | + for (i = 0; i < nr_segments; i++) { | |
| 184 | 189 | if (image->segment[i].bufsz > image->segment[i].memsz) |
| 185 | 190 | goto out; |
| 186 | 191 | } |
| 187 | 192 | |
| 188 | − | |
| 189 | 193 | result = 0; |
| 190 | − out: | |
| 191 | − if (result == 0) { | |
| 194 | +out: | |
| 195 | + if (result == 0) | |
| 192 | 196 | *rimage = image; |
| 193 | − } else { | |
| 197 | + else | |
| 194 | 198 | kfree(image); |
| 195 | − } | |
| 199 | + | |
| 196 | 200 | return result; |
| 197 | 201 | |
| 198 | 202 | } |
| 199 | 203 | |
| 200 | 204 | static int kimage_normal_alloc(struct kimage **rimage, unsigned long entry, |
| 201 | − unsigned long nr_segments, struct kexec_segment __user *segments) | |
| 205 | + unsigned long nr_segments, | |
| 206 | + struct kexec_segment __user *segments) | |
| 202 | 207 | { |
| 203 | 208 | int result; |
| 204 | 209 | struct kimage *image; |
| @@ -206,9 +211,9 @@ static int kimage_normal_alloc(struct kimage **rimage, unsigned long entry, · 1 unmodified line | ||
| 206 | 211 | /* Allocate and initialize a controlling structure */ |
| 207 | 212 | image = NULL; |
| 208 | 213 | result = do_kimage_alloc(&image, entry, nr_segments, segments); |
| 209 | − if (result) { | |
| 214 | + if (result) | |
| 210 | 215 | goto out; |
| 211 | − } | |
| 216 | + | |
| 212 | 217 | *rimage = image; |
| 213 | 218 | |
| 214 | 219 | /* |
| @@ -218,7 +223,7 @@ static int kimage_normal_alloc(struct kimage **rimage, unsigned long entry, · 3 unmodified lines | ||
| 218 | 223 | */ |
| 219 | 224 | result = -ENOMEM; |
| 220 | 225 | image->control_code_page = kimage_alloc_control_pages(image, |
| 221 | − get_order(KEXEC_CONTROL_CODE_SIZE)); | |
| 226 | + get_order(KEXEC_CONTROL_CODE_SIZE)); | |
| 222 | 227 | if (!image->control_code_page) { |
| 223 | 228 | printk(KERN_ERR "Could not allocate control_code_buffer\n"); |
| 224 | 229 | goto out; |
| @@ -226,16 +231,17 @@ static int kimage_normal_alloc(struct kimage **rimage, unsigned long entry, · 1 unmodified line | ||
| 226 | 231 | |
| 227 | 232 | result = 0; |
| 228 | 233 | out: |
| 229 | − if (result == 0) { | |
| 234 | + if (result == 0) | |
| 230 | 235 | *rimage = image; |
| 231 | − } else { | |
| 236 | + else | |
| 232 | 237 | kfree(image); |
| 233 | − } | |
| 238 | + | |
| 234 | 239 | return result; |
| 235 | 240 | } |
| 236 | 241 | |
| 237 | 242 | static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry, |
| 238 | − unsigned long nr_segments, struct kexec_segment *segments) | |
| 243 | + unsigned long nr_segments, | |
| 244 | + struct kexec_segment *segments) | |
| 239 | 245 | { |
| 240 | 246 | int result; |
| 241 | 247 | struct kimage *image; |
| @@ -250,9 +256,8 @@ static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry, · 8 unmodified lines | ||
| 250 | 256 | |
| 251 | 257 | /* Allocate and initialize a controlling structure */ |
| 252 | 258 | result = do_kimage_alloc(&image, entry, nr_segments, segments); |
| 253 | − if (result) { | |
| 259 | + if (result) | |
| 254 | 260 | goto out; |
| 255 | − } | |
| 256 | 261 | |
| 257 | 262 | /* Enable the special crash kernel control page |
| 258 | 263 | * allocation policy. |
| @@ -272,6 +277,7 @@ static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry, · 13 unmodified lines | ||
| 272 | 277 | result = -EADDRNOTAVAIL; |
| 273 | 278 | for (i = 0; i < nr_segments; i++) { |
| 274 | 279 | unsigned long mstart, mend; |
| 280 | + | |
| 275 | 281 | mstart = image->segment[i].mem; |
| 276 | 282 | mend = mstart + image->segment[i].memsz - 1; |
| 277 | 283 | /* Ensure we are within the crash kernel limits */ |
| @@ -279,7 +285,6 @@ static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry, · 1 unmodified line | ||
| 279 | 285 | goto out; |
| 280 | 286 | } |
| 281 | 287 | |
| 282 | − | |
| 283 | 288 | /* |
| 284 | 289 | * Find a location for the control code buffer, and add |
| 285 | 290 | * the vector of segments so that it's pages will also be |
| @@ -287,80 +292,84 @@ static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry, · 1 unmodified line | ||
| 287 | 292 | */ |
| 288 | 293 | result = -ENOMEM; |
| 289 | 294 | image->control_code_page = kimage_alloc_control_pages(image, |
| 290 | − get_order(KEXEC_CONTROL_CODE_SIZE)); | |
| 295 | + get_order(KEXEC_CONTROL_CODE_SIZE)); | |
| 291 | 296 | if (!image->control_code_page) { |
| 292 | 297 | printk(KERN_ERR "Could not allocate control_code_buffer\n"); |
| 293 | 298 | goto out; |
| 294 | 299 | } |
| 295 | 300 | |
| 296 | 301 | result = 0; |
| 297 | − out: | |
| 298 | − if (result == 0) { | |
| 302 | +out: | |
| 303 | + if (result == 0) | |
| 299 | 304 | *rimage = image; |
| 300 | − } else { | |
| 305 | + else | |
| 301 | 306 | kfree(image); |
| 302 | − } | |
| 307 | + | |
| 303 | 308 | return result; |
| 304 | 309 | } |
| 305 | 310 | |
| 306 | −static int kimage_is_destination_range( | |
| 307 | − struct kimage *image, unsigned long start, unsigned long end) | |
| 311 | +static int kimage_is_destination_range(struct kimage *image, | |
| 312 | + unsigned long start, | |
| 313 | + unsigned long end) | |
| 308 | 314 | { |
| 309 | 315 | unsigned long i; |
| 310 | 316 | |
| 311 | 317 | for (i = 0; i < image->nr_segments; i++) { |
| 312 | 318 | unsigned long mstart, mend; |
| 319 | + | |
| 313 | 320 | mstart = image->segment[i].mem; |
| 314 | − mend = mstart + image->segment[i].memsz; | |
| 315 | − if ((end > mstart) && (start < mend)) { | |
| 321 | + mend = mstart + image->segment[i].memsz; | |
| 322 | + if ((end > mstart) && (start < mend)) | |
| 316 | 323 | return 1; |
| 317 | − } | |
| 318 | 324 | } |
| 325 | + | |
| 319 | 326 | return 0; |
| 320 | 327 | } |
| 321 | 328 | |
| 322 | −static struct page *kimage_alloc_pages(unsigned int gfp_mask, unsigned int order) | |
| 329 | +static struct page *kimage_alloc_pages(unsigned int gfp_mask, | |
| 330 | + unsigned int order) | |
| 323 | 331 | { |
| 324 | 332 | struct page *pages; |
| 333 | + | |
| 325 | 334 | pages = alloc_pages(gfp_mask, order); |
| 326 | 335 | if (pages) { |
| 327 | 336 | unsigned int count, i; |
| 328 | 337 | pages->mapping = NULL; |
| 329 | 338 | pages->private = order; |
| 330 | 339 | count = 1 << order; |
| 331 | − for(i = 0; i < count; i++) { | |
| 340 | + for (i = 0; i < count; i++) | |
| 332 | 341 | SetPageReserved(pages + i); |
| 333 | − } | |
| 334 | 342 | } |
| 343 | + | |
| 335 | 344 | return pages; |
| 336 | 345 | } |
| 337 | 346 | |
| 338 | 347 | static void kimage_free_pages(struct page *page) |
| 339 | 348 | { |
| 340 | 349 | unsigned int order, count, i; |
| 350 | + | |
| 341 | 351 | order = page->private; |
| 342 | 352 | count = 1 << order; |
| 343 | − for(i = 0; i < count; i++) { | |
| 353 | + for (i = 0; i < count; i++) | |
| 344 | 354 | ClearPageReserved(page + i); |
| 345 | − } | |
| 346 | 355 | __free_pages(page, order); |
| 347 | 356 | } |
| 348 | 357 | |
| 349 | 358 | static void kimage_free_page_list(struct list_head *list) |
| 350 | 359 | { |
| 351 | 360 | struct list_head *pos, *next; |
| 361 | + | |
| 352 | 362 | list_for_each_safe(pos, next, list) { |
| 353 | 363 | struct page *page; |
| 354 | 364 | |
| 355 | 365 | page = list_entry(pos, struct page, lru); |
| 356 | 366 | list_del(&page->lru); |
| 357 | − | |
| 358 | 367 | kimage_free_pages(page); |
| 359 | 368 | } |
| 360 | 369 | } |
| 361 | 370 | |
| 362 | −static struct page *kimage_alloc_normal_control_pages( | |
| 363 | − struct kimage *image, unsigned int order) | |
| 371 | +static struct page *kimage_alloc_normal_control_pages(struct kimage *image, | |
| 372 | + unsigned int order) | |
| 364 | 373 | { |
| 365 | 374 | /* Control pages are special, they are the intermediaries |
| 366 | 375 | * that are needed while we copy the rest of the pages |
| @@ -387,6 +396,7 @@ static struct page *kimage_alloc_normal_control_pages( · 20 unmodified lines | ||
| 387 | 396 | */ |
| 388 | 397 | do { |
| 389 | 398 | unsigned long pfn, epfn, addr, eaddr; |
| 399 | + | |
| 390 | 400 | pages = kimage_alloc_pages(GFP_KERNEL, order); |
| 391 | 401 | if (!pages) |
| 392 | 402 | break; |
| @@ -395,12 +405,12 @@ static struct page *kimage_alloc_normal_control_pages( · 2 unmodified lines | ||
| 395 | 405 | addr = pfn << PAGE_SHIFT; |
| 396 | 406 | eaddr = epfn << PAGE_SHIFT; |
| 397 | 407 | if ((epfn >= (KEXEC_CONTROL_MEMORY_LIMIT >> PAGE_SHIFT)) || |
| 398 | − kimage_is_destination_range(image, addr, eaddr)) | |
| 399 | − { | |
| 408 | + kimage_is_destination_range(image, addr, eaddr)) { | |
| 400 | 409 | list_add(&pages->lru, &extra_pages); |
| 401 | 410 | pages = NULL; |
| 402 | 411 | } |
| 403 | − } while(!pages); | |
| 412 | + } while (!pages); | |
| 413 | + | |
| 404 | 414 | if (pages) { |
| 405 | 415 | /* Remember the allocated page... */ |
| 406 | 416 | list_add(&pages->lru, &image->control_pages); |
| @@ -420,12 +430,12 @@ static struct page *kimage_alloc_normal_control_pages( · 13 unmodified lines | ||
| 420 | 430 | * For now it is simpler to just free the pages. |
| 421 | 431 | */ |
| 422 | 432 | kimage_free_page_list(&extra_pages); |
| 423 | − return pages; | |
| 424 | 433 | |
| 434 | + return pages; | |
| 425 | 435 | } |
| 426 | 436 | |
| 427 | −static struct page *kimage_alloc_crash_control_pages( | |
| 428 | − struct kimage *image, unsigned int order) | |
| 437 | +static struct page *kimage_alloc_crash_control_pages(struct kimage *image, | |
| 438 | + unsigned int order) | |
| 429 | 439 | { |
| 430 | 440 | /* Control pages are special, they are the intermediaries |
| 431 | 441 | * that are needed while we copy the rest of the pages |
| @@ -450,21 +460,22 @@ static struct page *kimage_alloc_crash_control_pages( · 18 unmodified lines | ||
| 450 | 460 | */ |
| 451 | 461 | unsigned long hole_start, hole_end, size; |
| 452 | 462 | struct page *pages; |
| 463 | + | |
| 453 | 464 | pages = NULL; |
| 454 | 465 | size = (1 << order) << PAGE_SHIFT; |
| 455 | 466 | hole_start = (image->control_page + (size - 1)) & ~(size - 1); |
| 456 | 467 | hole_end = hole_start + size - 1; |
| 457 | − while(hole_end <= crashk_res.end) { | |
| 468 | + while (hole_end <= crashk_res.end) { | |
| 458 | 469 | unsigned long i; |
| 459 | − if (hole_end > KEXEC_CONTROL_MEMORY_LIMIT) { | |
| 470 | + | |
| 471 | + if (hole_end > KEXEC_CONTROL_MEMORY_LIMIT) | |
| 460 | 472 | break; |
| 461 | − } | |
| 462 | − if (hole_end > crashk_res.end) { | |
| 473 | + if (hole_end > crashk_res.end) | |
| 463 | 474 | break; |
| 464 | − } | |
| 465 | 475 | /* See if I overlap any of the segments */ |
| 466 | − for(i = 0; i < image->nr_segments; i++) { | |
| 476 | + for (i = 0; i < image->nr_segments; i++) { | |
| 467 | 477 | unsigned long mstart, mend; |
| 478 | + | |
| 468 | 479 | mstart = image->segment[i].mem; |
| 469 | 480 | mend = mstart + image->segment[i].memsz - 1; |
| 470 | 481 | if ((hole_end >= mstart) && (hole_start <= mend)) { |
| @@ -480,18 +491,19 @@ static struct page *kimage_alloc_crash_control_pages( · 9 unmodified lines | ||
| 480 | 491 | break; |
| 481 | 492 | } |
| 482 | 493 | } |
| 483 | − if (pages) { | |
| 494 | + if (pages) | |
| 484 | 495 | image->control_page = hole_end; |
| 485 | − } | |
| 496 | + | |
| 486 | 497 | return pages; |
| 487 | 498 | } |
| 488 | 499 | |
| 489 | 500 | |
| 490 | −struct page *kimage_alloc_control_pages( | |
| 491 | − struct kimage *image, unsigned int order) | |
| 501 | +struct page *kimage_alloc_control_pages(struct kimage *image, | |
| 502 | + unsigned int order) | |
| 492 | 503 | { |
| 493 | 504 | struct page *pages = NULL; |
| 494 | − switch(image->type) { | |
| 505 | + | |
| 506 | + switch (image->type) { | |
| 495 | 507 | case KEXEC_TYPE_DEFAULT: |
| 496 | 508 | pages = kimage_alloc_normal_control_pages(image, order); |
| 497 | 509 | break; |
| @@ -499,43 +511,46 @@ struct page *kimage_alloc_control_pages( · 1 unmodified line | ||
| 499 | 511 | pages = kimage_alloc_crash_control_pages(image, order); |
| 500 | 512 | break; |
| 501 | 513 | } |
| 514 | + | |
| 502 | 515 | return pages; |
| 503 | 516 | } |
| 504 | 517 | |
| 505 | 518 | static int kimage_add_entry(struct kimage *image, kimage_entry_t entry) |
| 506 | 519 | { |
| 507 | − if (*image->entry != 0) { | |
| 520 | + if (*image->entry != 0) | |
| 508 | 521 | image->entry++; |
| 509 | − } | |
| 522 | + | |
| 510 | 523 | if (image->entry == image->last_entry) { |
| 511 | 524 | kimage_entry_t *ind_page; |
| 512 | 525 | struct page *page; |
| 526 | + | |
| 513 | 527 | page = kimage_alloc_page(image, GFP_KERNEL, KIMAGE_NO_DEST); |
| 514 | − if (!page) { | |
| 528 | + if (!page) | |
| 515 | 529 | return -ENOMEM; |
| 516 | − } | |
| 530 | + | |
| 517 | 531 | ind_page = page_address(page); |
| 518 | 532 | *image->entry = virt_to_phys(ind_page) | IND_INDIRECTION; |
| 519 | 533 | image->entry = ind_page; |
| 520 | − image->last_entry = | |
| 521 | − ind_page + ((PAGE_SIZE/sizeof(kimage_entry_t)) - 1); | |
| 534 | + image->last_entry = ind_page + | |
| 535 | + ((PAGE_SIZE/sizeof(kimage_entry_t)) - 1); | |
| 522 | 536 | } |
| 523 | 537 | *image->entry = entry; |
| 524 | 538 | image->entry++; |
| 525 | 539 | *image->entry = 0; |
| 540 | + | |
| 526 | 541 | return 0; |
| 527 | 542 | } |
| 528 | 543 | |
| 529 | −static int kimage_set_destination( | |
| 530 | − struct kimage *image, unsigned long destination) | |
| 544 | +static int kimage_set_destination(struct kimage *image, | |
| 545 | + unsigned long destination) | |
| 531 | 546 | { |
| 532 | 547 | int result; |
| 533 | 548 | |
| 534 | 549 | destination &= PAGE_MASK; |
| 535 | 550 | result = kimage_add_entry(image, destination | IND_DESTINATION); |
| 536 | − if (result == 0) { | |
| 551 | + if (result == 0) | |
| 537 | 552 | image->destination = destination; |
| 538 | − } | |
| 553 | + | |
| 539 | 554 | return result; |
| 540 | 555 | } |
| 541 | 556 | |
| @@ -546,9 +561,9 @@ static int kimage_add_page(struct kimage *image, unsigned long page) · 4 unmodified lines | ||
| 546 | 561 | |
| 547 | 562 | page &= PAGE_MASK; |
| 548 | 563 | result = kimage_add_entry(image, page | IND_SOURCE); |
| 549 | − if (result == 0) { | |
| 564 | + if (result == 0) | |
| 550 | 565 | image->destination += PAGE_SIZE; |
| 551 | − } | |
| 566 | + | |
| 552 | 567 | return result; |
| 553 | 568 | } |
| 554 | 569 | |
| @@ -564,10 +579,11 @@ static void kimage_free_extra_pages(struct kimage *image) · 9 unmodified lines | ||
| 564 | 579 | } |
| 565 | 580 | static int kimage_terminate(struct kimage *image) |
| 566 | 581 | { |
| 567 | − if (*image->entry != 0) { | |
| 582 | + if (*image->entry != 0) | |
| 568 | 583 | image->entry++; |
| 569 | − } | |
| 584 | + | |
| 570 | 585 | *image->entry = IND_DONE; |
| 586 | + | |
| 571 | 587 | return 0; |
| 572 | 588 | } |
| 573 | 589 | |
| @@ -591,26 +607,24 @@ static void kimage_free(struct kimage *image) · 17 unmodified lines | ||
| 591 | 607 | |
| 592 | 608 | if (!image) |
| 593 | 609 | return; |
| 610 | + | |
| 594 | 611 | kimage_free_extra_pages(image); |
| 595 | 612 | for_each_kimage_entry(image, ptr, entry) { |
| 596 | 613 | if (entry & IND_INDIRECTION) { |
| 597 | 614 | /* Free the previous indirection page */ |
| 598 | − if (ind & IND_INDIRECTION) { | |
| 615 | + if (ind & IND_INDIRECTION) | |
| 599 | 616 | kimage_free_entry(ind); |
| 600 | − } | |
| 601 | 617 | /* Save this indirection page until we are |
| 602 | 618 | * done with it. |
| 603 | 619 | */ |
| 604 | 620 | ind = entry; |
| 605 | 621 | } |
| 606 | − else if (entry & IND_SOURCE) { | |
| 622 | + else if (entry & IND_SOURCE) | |
| 607 | 623 | kimage_free_entry(entry); |
| 608 | − } | |
| 609 | 624 | } |
| 610 | 625 | /* Free the final indirection page */ |
| 611 | − if (ind & IND_INDIRECTION) { | |
| 626 | + if (ind & IND_INDIRECTION) | |
| 612 | 627 | kimage_free_entry(ind); |
| 613 | − } | |
| 614 | 628 | |
| 615 | 629 | /* Handle any machine specific cleanup */ |
| 616 | 630 | machine_kexec_cleanup(image); |
| @@ -620,26 +634,28 @@ static void kimage_free(struct kimage *image) · 3 unmodified lines | ||
| 620 | 634 | kfree(image); |
| 621 | 635 | } |
| 622 | 636 | |
| 623 | −static kimage_entry_t *kimage_dst_used(struct kimage *image, unsigned long page) | |
| 637 | +static kimage_entry_t *kimage_dst_used(struct kimage *image, | |
| 638 | + unsigned long page) | |
| 624 | 639 | { |
| 625 | 640 | kimage_entry_t *ptr, entry; |
| 626 | 641 | unsigned long destination = 0; |
| 627 | 642 | |
| 628 | 643 | for_each_kimage_entry(image, ptr, entry) { |
| 629 | − if (entry & IND_DESTINATION) { | |
| 644 | + if (entry & IND_DESTINATION) | |
| 630 | 645 | destination = entry & PAGE_MASK; |
| 631 | − } | |
| 632 | 646 | else if (entry & IND_SOURCE) { |
| 633 | − if (page == destination) { | |
| 647 | + if (page == destination) | |
| 634 | 648 | return ptr; |
| 635 | − } | |
| 636 | 649 | destination += PAGE_SIZE; |
| 637 | 650 | } |
| 638 | 651 | } |
| 652 | + | |
| 639 | 653 | return 0; |
| 640 | 654 | } |
| 641 | 655 | |
| 642 | −static struct page *kimage_alloc_page(struct kimage *image, unsigned int gfp_mask, unsigned long destination) | |
| 656 | +static struct page *kimage_alloc_page(struct kimage *image, | |
| 657 | + unsigned int gfp_mask, | |
| 658 | + unsigned long destination) | |
| 643 | 659 | { |
| 644 | 660 | /* |
| 645 | 661 | * Here we implement safeguards to ensure that a source page |
| @@ -679,11 +695,11 @@ static struct page *kimage_alloc_page(struct kimage *image, unsigned int gfp_mas · 33 unmodified lines | ||
| 679 | 695 | |
| 680 | 696 | /* Allocate a page, if we run out of memory give up */ |
| 681 | 697 | page = kimage_alloc_pages(gfp_mask, 0); |
| 682 | − if (!page) { | |
| 698 | + if (!page) | |
| 683 | 699 | return 0; |
| 684 | − } | |
| 685 | 700 | /* If the page cannot be used file it away */ |
| 686 | − if (page_to_pfn(page) > (KEXEC_SOURCE_MEMORY_LIMIT >> PAGE_SHIFT)) { | |
| 701 | + if (page_to_pfn(page) > | |
| 702 | + (KEXEC_SOURCE_MEMORY_LIMIT >> PAGE_SHIFT)) { | |
| 687 | 703 | list_add(&page->lru, &image->unuseable_pages); |
| 688 | 704 | continue; |
| 689 | 705 | } |
| @@ -694,7 +710,8 @@ static struct page *kimage_alloc_page(struct kimage *image, unsigned int gfp_mas · 4 unmodified lines | ||
| 694 | 710 | break; |
| 695 | 711 | |
| 696 | 712 | /* If the page is not a destination page use it */ |
| 697 | − if (!kimage_is_destination_range(image, addr, addr + PAGE_SIZE)) | |
| 713 | + if (!kimage_is_destination_range(image, addr, | |
| 714 | + addr + PAGE_SIZE)) | |
| 698 | 715 | break; |
| 699 | 716 | |
| 700 | 717 | /* |
| @@ -727,11 +744,12 @@ static struct page *kimage_alloc_page(struct kimage *image, unsigned int gfp_mas · 26 unmodified lines | ||
| 727 | 744 | list_add(&page->lru, &image->dest_pages); |
| 728 | 745 | } |
| 729 | 746 | } |
| 747 | + | |
| 730 | 748 | return page; |
| 731 | 749 | } |
| 732 | 750 | |
| 733 | 751 | static int kimage_load_normal_segment(struct kimage *image, |
| 734 | − struct kexec_segment *segment) | |
| 752 | + struct kexec_segment *segment) | |
| 735 | 753 | { |
| 736 | 754 | unsigned long maddr; |
| 737 | 755 | unsigned long ubytes, mbytes; |
| @@ -745,34 +763,36 @@ static int kimage_load_normal_segment(struct kimage *image, · 7 unmodified lines | ||
| 745 | 763 | maddr = segment->mem; |
| 746 | 764 | |
| 747 | 765 | result = kimage_set_destination(image, maddr); |
| 748 | − if (result < 0) { | |
| 766 | + if (result < 0) | |
| 749 | 767 | goto out; |
| 750 | − } | |
| 751 | − while(mbytes) { | |
| 768 | + | |
| 769 | + while (mbytes) { | |
| 752 | 770 | struct page *page; |
| 753 | 771 | char *ptr; |
| 754 | 772 | size_t uchunk, mchunk; |
| 773 | + | |
| 755 | 774 | page = kimage_alloc_page(image, GFP_HIGHUSER, maddr); |
| 756 | 775 | if (page == 0) { |
| 757 | 776 | result = -ENOMEM; |
| 758 | 777 | goto out; |
| 759 | 778 | } |
| 760 | − result = kimage_add_page(image, page_to_pfn(page) << PAGE_SHIFT); | |
| 761 | − if (result < 0) { | |
| 779 | + result = kimage_add_page(image, page_to_pfn(page) | |
| 780 | + << PAGE_SHIFT); | |
| 781 | + if (result < 0) | |
| 762 | 782 | goto out; |
| 763 | − } | |
| 783 | + | |
| 764 | 784 | ptr = kmap(page); |
| 765 | 785 | /* Start with a clear page */ |
| 766 | 786 | memset(ptr, 0, PAGE_SIZE); |
| 767 | 787 | ptr += maddr & ~PAGE_MASK; |
| 768 | 788 | mchunk = PAGE_SIZE - (maddr & ~PAGE_MASK); |
| 769 | − if (mchunk > mbytes) { | |
| 789 | + if (mchunk > mbytes) | |
| 770 | 790 | mchunk = mbytes; |
| 771 | − } | |
| 791 | + | |
| 772 | 792 | uchunk = mchunk; |
| 773 | − if (uchunk > ubytes) { | |
| 793 | + if (uchunk > ubytes) | |
| 774 | 794 | uchunk = ubytes; |
| 775 | − } | |
| 795 | + | |
| 776 | 796 | result = copy_from_user(ptr, buf, uchunk); |
| 777 | 797 | kunmap(page); |
| 778 | 798 | if (result) { |
| @@ -784,12 +804,12 @@ static int kimage_load_normal_segment(struct kimage *image, · 5 unmodified lines | ||
| 784 | 804 | buf += mchunk; |
| 785 | 805 | mbytes -= mchunk; |
| 786 | 806 | } |
| 787 | − out: | |
| 807 | +out: | |
| 788 | 808 | return result; |
| 789 | 809 | } |
| 790 | 810 | |
| 791 | 811 | static int kimage_load_crash_segment(struct kimage *image, |
| 792 | − struct kexec_segment *segment) | |
| 812 | + struct kexec_segment *segment) | |
| 793 | 813 | { |
| 794 | 814 | /* For crash dumps kernels we simply copy the data from |
| 795 | 815 | * user space to it's destination. |
| @@ -805,10 +825,11 @@ static int kimage_load_crash_segment(struct kimage *image, · 9 unmodified lines | ||
| 805 | 825 | ubytes = segment->bufsz; |
| 806 | 826 | mbytes = segment->memsz; |
| 807 | 827 | maddr = segment->mem; |
| 808 | − while(mbytes) { | |
| 828 | + while (mbytes) { | |
| 809 | 829 | struct page *page; |
| 810 | 830 | char *ptr; |
| 811 | 831 | size_t uchunk, mchunk; |
| 832 | + | |
| 812 | 833 | page = pfn_to_page(maddr >> PAGE_SHIFT); |
| 813 | 834 | if (page == 0) { |
| 814 | 835 | result = -ENOMEM; |
| @@ -817,9 +838,9 @@ static int kimage_load_crash_segment(struct kimage *image, · 2 unmodified lines | ||
| 817 | 838 | ptr = kmap(page); |
| 818 | 839 | ptr += maddr & ~PAGE_MASK; |
| 819 | 840 | mchunk = PAGE_SIZE - (maddr & ~PAGE_MASK); |
| 820 | − if (mchunk > mbytes) { | |
| 841 | + if (mchunk > mbytes) | |
| 821 | 842 | mchunk = mbytes; |
| 822 | − } | |
| 843 | + | |
| 823 | 844 | uchunk = mchunk; |
| 824 | 845 | if (uchunk > ubytes) { |
| 825 | 846 | uchunk = ubytes; |
| @@ -837,15 +858,16 @@ static int kimage_load_crash_segment(struct kimage *image, · 11 unmodified lines | ||
| 837 | 858 | buf += mchunk; |
| 838 | 859 | mbytes -= mchunk; |
| 839 | 860 | } |
| 840 | − out: | |
| 861 | +out: | |
| 841 | 862 | return result; |
| 842 | 863 | } |
| 843 | 864 | |
| 844 | 865 | static int kimage_load_segment(struct kimage *image, |
| 845 | − struct kexec_segment *segment) | |
| 866 | + struct kexec_segment *segment) | |
| 846 | 867 | { |
| 847 | 868 | int result = -ENOMEM; |
| 848 | − switch(image->type) { | |
| 869 | + | |
| 870 | + switch (image->type) { | |
| 849 | 871 | case KEXEC_TYPE_DEFAULT: |
| 850 | 872 | result = kimage_load_normal_segment(image, segment); |
| 851 | 873 | break; |
| @@ -853,6 +875,7 @@ static int kimage_load_segment(struct kimage *image, · 1 unmodified line | ||
| 853 | 875 | result = kimage_load_crash_segment(image, segment); |
| 854 | 876 | break; |
| 855 | 877 | } |
| 878 | + | |
| 856 | 879 | return result; |
| 857 | 880 | } |
| 858 | 881 | |
| @@ -885,9 +908,9 @@ static struct kimage *kexec_crash_image = NULL; · 26 unmodified lines | ||
| 885 | 908 | */ |
| 886 | 909 | static int kexec_lock = 0; |
| 887 | 910 | |
| 888 | −asmlinkage long sys_kexec_load(unsigned long entry, | |
| 889 | − unsigned long nr_segments, struct kexec_segment __user *segments, | |
| 890 | − unsigned long flags) | |
| 911 | +asmlinkage long sys_kexec_load(unsigned long entry, unsigned long nr_segments, | |
| 912 | + struct kexec_segment __user *segments, | |
| 913 | + unsigned long flags) | |
| 891 | 914 | { |
| 892 | 915 | struct kimage **dest_image, *image; |
| 893 | 916 | int locked; |
| @@ -907,9 +930,7 @@ asmlinkage long sys_kexec_load(unsigned long entry, · 13 unmodified lines | ||
| 907 | 930 | /* Verify we are on the appropriate architecture */ |
| 908 | 931 | if (((flags & KEXEC_ARCH_MASK) != KEXEC_ARCH) && |
| 909 | 932 | ((flags & KEXEC_ARCH_MASK) != KEXEC_ARCH_DEFAULT)) |
| 910 | − { | |
| 911 | 933 | return -EINVAL; |
| 912 | − } | |
| 913 | 934 | |
| 914 | 935 | /* Put an artificial cap on the number |
| 915 | 936 | * of segments passed to kexec_load. |
| @@ -929,58 +950,59 @@ asmlinkage long sys_kexec_load(unsigned long entry, · 13 unmodified lines | ||
| 929 | 950 | * KISS: always take the mutex. |
| 930 | 951 | */ |
| 931 | 952 | locked = xchg(&kexec_lock, 1); |
| 932 | − if (locked) { | |
| 953 | + if (locked) | |
| 933 | 954 | return -EBUSY; |
| 934 | − } | |
| 955 | + | |
| 935 | 956 | dest_image = &kexec_image; |
| 936 | − if (flags & KEXEC_ON_CRASH) { | |
| 957 | + if (flags & KEXEC_ON_CRASH) | |
| 937 | 958 | dest_image = &kexec_crash_image; |
| 938 | − } | |
| 939 | 959 | if (nr_segments > 0) { |
| 940 | 960 | unsigned long i; |
| 961 | + | |
| 941 | 962 | /* Loading another kernel to reboot into */ |
| 942 | − if ((flags & KEXEC_ON_CRASH) == 0) { | |
| 943 | − result = kimage_normal_alloc(&image, entry, nr_segments, segments); | |
| 944 | − } | |
| 963 | + if ((flags & KEXEC_ON_CRASH) == 0) | |
| 964 | + result = kimage_normal_alloc(&image, entry, | |
| 965 | + nr_segments, segments); | |
| 945 | 966 | /* Loading another kernel to switch to if this one crashes */ |
| 946 | 967 | else if (flags & KEXEC_ON_CRASH) { |
| 947 | 968 | /* Free any current crash dump kernel before |
| 948 | 969 | * we corrupt it. |
| 949 | 970 | */ |
| 950 | 971 | kimage_free(xchg(&kexec_crash_image, NULL)); |
| 951 | − result = kimage_crash_alloc(&image, entry, nr_segments, segments); | |
| 972 | + result = kimage_crash_alloc(&image, entry, | |
| 973 | + nr_segments, segments); | |
| 952 | 974 | } |
| 953 | − if (result) { | |
| 975 | + if (result) | |
| 954 | 976 | goto out; |
| 955 | − } | |
| 977 | + | |
| 956 | 978 | result = machine_kexec_prepare(image); |
| 957 | − if (result) { | |
| 979 | + if (result) | |
| 958 | 980 | goto out; |
| 959 | − } | |
| 960 | − for(i = 0; i < nr_segments; i++) { | |
| 981 | + | |
| 982 | + for (i = 0; i < nr_segments; i++) { | |
| 961 | 983 | result = kimage_load_segment(image, &image->segment[i]); |
| 962 | − if (result) { | |
| 984 | + if (result) | |
| 963 | 985 | goto out; |
| 964 | − } | |
| 965 | 986 | } |
| 966 | 987 | result = kimage_terminate(image); |
| 967 | − if (result) { | |
| 988 | + if (result) | |
| 968 | 989 | goto out; |
| 969 | − } | |
| 970 | 990 | } |
| 971 | 991 | /* Install the new kernel, and Uninstall the old */ |
| 972 | 992 | image = xchg(dest_image, image); |
| 973 | 993 | |
| 974 | − out: | |
| 994 | +out: | |
| 975 | 995 | xchg(&kexec_lock, 0); /* Release the mutex */ |
| 976 | 996 | kimage_free(image); |
| 997 | + | |
| 977 | 998 | return result; |
| 978 | 999 | } |
| 979 | 1000 | |
| 980 | 1001 | #ifdef CONFIG_COMPAT |
| 981 | 1002 | asmlinkage long compat_sys_kexec_load(unsigned long entry, |
| 982 | − unsigned long nr_segments, struct compat_kexec_segment __user *segments, | |
| 983 | − unsigned long flags) | |
| 1003 | + unsigned long nr_segments, | |
| 1004 | + struct compat_kexec_segment __user *segments, | |
| 1005 | + unsigned long flags) | |
| 984 | 1006 | { |
| 985 | 1007 | struct compat_kexec_segment in; |
| 986 | 1008 | struct kexec_segment out, __user *ksegments; |
| @@ -989,20 +1011,17 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry, · 2 unmodified lines | ||
| 989 | 1011 | /* Don't allow clients that don't understand the native |
| 990 | 1012 | * architecture to do anything. |
| 991 | 1013 | */ |
| 992 | − if ((flags & KEXEC_ARCH_MASK) == KEXEC_ARCH_DEFAULT) { | |
| 1014 | + if ((flags & KEXEC_ARCH_MASK) == KEXEC_ARCH_DEFAULT) | |
| 993 | 1015 | return -EINVAL; |
| 994 | − } | |
| 995 | 1016 | |
| 996 | − if (nr_segments > KEXEC_SEGMENT_MAX) { | |
| 1017 | + if (nr_segments > KEXEC_SEGMENT_MAX) | |
| 997 | 1018 | return -EINVAL; |
| 998 | − } | |
| 999 | 1019 | |
| 1000 | 1020 | ksegments = compat_alloc_user_space(nr_segments * sizeof(out)); |
| 1001 | 1021 | for (i=0; i < nr_segments; i++) { |
| 1002 | 1022 | result = copy_from_user(&in, &segments[i], sizeof(in)); |
| 1003 | − if (result) { | |
| 1023 | + if (result) | |
| 1004 | 1024 | return -EFAULT; |
| 1005 | − } | |
| 1006 | 1025 | |
| 1007 | 1026 | out.buf = compat_ptr(in.buf); |
| 1008 | 1027 | out.bufsz = in.bufsz; |
| @@ -1010,9 +1029,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry, · 1 unmodified line | ||
| 1010 | 1029 | out.memsz = in.memsz; |
| 1011 | 1030 | |
| 1012 | 1031 | result = copy_to_user(&ksegments[i], &out, sizeof(out)); |
| 1013 | − if (result) { | |
| 1032 | + if (result) | |
| 1014 | 1033 | return -EFAULT; |
| 1015 | − } | |
| 1016 | 1034 | } |
| 1017 | 1035 | |
| 1018 | 1036 | return sys_kexec_load(entry, nr_segments, ksegments, flags); |