History

[PATCH] kexec code cleanup

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 "*/"

Maneesh Soni committed 21 years ago

Commit 72414d31 parent 4f339ec10 files · +243 −211Browse files

Showing the changes to kernel (1 of 10 files). Show all

Unified · Split

kernel/kexec.c+160−142
@@ -87,12 +87,15 @@ int kexec_should_crash(struct task_struct *p) · 86 unmodified lines
8787 */
8888 #define KIMAGE_NO_DEST (-1UL)
8989
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);
9395
9496 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)
9699 {
97100 size_t segment_bytes;
98101 struct kimage *image;
@@ -102,9 +105,9 @@ static int do_kimage_alloc(struct kimage **rimage, unsigned long entry, · 3 unmodified lines
102105 /* Allocate a controlling structure */
103106 result = -ENOMEM;
104107 image = kmalloc(sizeof(*image), GFP_KERNEL);
105− if (!image) {
108+ if (!image)
106109 goto out;
107− }
110+
108111 memset(image, 0, sizeof(*image));
109112 image->head = 0;
110113 image->entry = &image->head;
@@ -145,6 +148,7 @@ static int do_kimage_alloc(struct kimage **rimage, unsigned long entry, · 34 unmodified lines
145148 result = -EADDRNOTAVAIL;
146149 for (i = 0; i < nr_segments; i++) {
147150 unsigned long mstart, mend;
151+
148152 mstart = image->segment[i].mem;
149153 mend = mstart + image->segment[i].memsz;
150154 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
159163 * easy explanation as one segment stops on another.
160164 */
161165 result = -EINVAL;
162− for(i = 0; i < nr_segments; i++) {
166+ for (i = 0; i < nr_segments; i++) {
163167 unsigned long mstart, mend;
164168 unsigned long j;
169+
165170 mstart = image->segment[i].mem;
166171 mend = mstart + image->segment[i].memsz;
167− for(j = 0; j < i; j++) {
172+ for (j = 0; j < i; j++) {
168173 unsigned long pstart, pend;
169174 pstart = image->segment[j].mem;
170175 pend = pstart + image->segment[j].memsz;
@@ -180,25 +185,25 @@ static int do_kimage_alloc(struct kimage **rimage, unsigned long entry, · 9 unmodified lines
180185 * later on.
181186 */
182187 result = -EINVAL;
183− for(i = 0; i < nr_segments; i++) {
188+ for (i = 0; i < nr_segments; i++) {
184189 if (image->segment[i].bufsz > image->segment[i].memsz)
185190 goto out;
186191 }
187192
188−
189193 result = 0;
190− out:
191− if (result == 0) {
194+out:
195+ if (result == 0)
192196 *rimage = image;
193− } else {
197+ else
194198 kfree(image);
195− }
199+
196200 return result;
197201
198202 }
199203
200204 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)
202207 {
203208 int result;
204209 struct kimage *image;
@@ -206,9 +211,9 @@ static int kimage_normal_alloc(struct kimage **rimage, unsigned long entry, · 1 unmodified line
206211 /* Allocate and initialize a controlling structure */
207212 image = NULL;
208213 result = do_kimage_alloc(&image, entry, nr_segments, segments);
209− if (result) {
214+ if (result)
210215 goto out;
211− }
216+
212217 *rimage = image;
213218
214219 /*
@@ -218,7 +223,7 @@ static int kimage_normal_alloc(struct kimage **rimage, unsigned long entry, · 3 unmodified lines
218223 */
219224 result = -ENOMEM;
220225 image->control_code_page = kimage_alloc_control_pages(image,
221− get_order(KEXEC_CONTROL_CODE_SIZE));
226+ get_order(KEXEC_CONTROL_CODE_SIZE));
222227 if (!image->control_code_page) {
223228 printk(KERN_ERR "Could not allocate control_code_buffer\n");
224229 goto out;
@@ -226,16 +231,17 @@ static int kimage_normal_alloc(struct kimage **rimage, unsigned long entry, · 1 unmodified line
226231
227232 result = 0;
228233 out:
229− if (result == 0) {
234+ if (result == 0)
230235 *rimage = image;
231− } else {
236+ else
232237 kfree(image);
233− }
238+
234239 return result;
235240 }
236241
237242 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)
239245 {
240246 int result;
241247 struct kimage *image;
@@ -250,9 +256,8 @@ static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry, · 8 unmodified lines
250256
251257 /* Allocate and initialize a controlling structure */
252258 result = do_kimage_alloc(&image, entry, nr_segments, segments);
253− if (result) {
259+ if (result)
254260 goto out;
255− }
256261
257262 /* Enable the special crash kernel control page
258263 * allocation policy.
@@ -272,6 +277,7 @@ static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry, · 13 unmodified lines
272277 result = -EADDRNOTAVAIL;
273278 for (i = 0; i < nr_segments; i++) {
274279 unsigned long mstart, mend;
280+
275281 mstart = image->segment[i].mem;
276282 mend = mstart + image->segment[i].memsz - 1;
277283 /* 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
279285 goto out;
280286 }
281287
282−
283288 /*
284289 * Find a location for the control code buffer, and add
285290 * 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
287292 */
288293 result = -ENOMEM;
289294 image->control_code_page = kimage_alloc_control_pages(image,
290− get_order(KEXEC_CONTROL_CODE_SIZE));
295+ get_order(KEXEC_CONTROL_CODE_SIZE));
291296 if (!image->control_code_page) {
292297 printk(KERN_ERR "Could not allocate control_code_buffer\n");
293298 goto out;
294299 }
295300
296301 result = 0;
297− out:
298− if (result == 0) {
302+out:
303+ if (result == 0)
299304 *rimage = image;
300− } else {
305+ else
301306 kfree(image);
302− }
307+
303308 return result;
304309 }
305310
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)
308314 {
309315 unsigned long i;
310316
311317 for (i = 0; i < image->nr_segments; i++) {
312318 unsigned long mstart, mend;
319+
313320 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))
316323 return 1;
317− }
318324 }
325+
319326 return 0;
320327 }
321328
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)
323331 {
324332 struct page *pages;
333+
325334 pages = alloc_pages(gfp_mask, order);
326335 if (pages) {
327336 unsigned int count, i;
328337 pages->mapping = NULL;
329338 pages->private = order;
330339 count = 1 << order;
331− for(i = 0; i < count; i++) {
340+ for (i = 0; i < count; i++)
332341 SetPageReserved(pages + i);
333− }
334342 }
343+
335344 return pages;
336345 }
337346
338347 static void kimage_free_pages(struct page *page)
339348 {
340349 unsigned int order, count, i;
350+
341351 order = page->private;
342352 count = 1 << order;
343− for(i = 0; i < count; i++) {
353+ for (i = 0; i < count; i++)
344354 ClearPageReserved(page + i);
345− }
346355 __free_pages(page, order);
347356 }
348357
349358 static void kimage_free_page_list(struct list_head *list)
350359 {
351360 struct list_head *pos, *next;
361+
352362 list_for_each_safe(pos, next, list) {
353363 struct page *page;
354364
355365 page = list_entry(pos, struct page, lru);
356366 list_del(&page->lru);
357−
358367 kimage_free_pages(page);
359368 }
360369 }
361370
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)
364373 {
365374 /* Control pages are special, they are the intermediaries
366375 * 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
387396 */
388397 do {
389398 unsigned long pfn, epfn, addr, eaddr;
399+
390400 pages = kimage_alloc_pages(GFP_KERNEL, order);
391401 if (!pages)
392402 break;
@@ -395,12 +405,12 @@ static struct page *kimage_alloc_normal_control_pages( · 2 unmodified lines
395405 addr = pfn << PAGE_SHIFT;
396406 eaddr = epfn << PAGE_SHIFT;
397407 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)) {
400409 list_add(&pages->lru, &extra_pages);
401410 pages = NULL;
402411 }
403− } while(!pages);
412+ } while (!pages);
413+
404414 if (pages) {
405415 /* Remember the allocated page... */
406416 list_add(&pages->lru, &image->control_pages);
@@ -420,12 +430,12 @@ static struct page *kimage_alloc_normal_control_pages( · 13 unmodified lines
420430 * For now it is simpler to just free the pages.
421431 */
422432 kimage_free_page_list(&extra_pages);
423− return pages;
424433
434+ return pages;
425435 }
426436
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)
429439 {
430440 /* Control pages are special, they are the intermediaries
431441 * 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
450460 */
451461 unsigned long hole_start, hole_end, size;
452462 struct page *pages;
463+
453464 pages = NULL;
454465 size = (1 << order) << PAGE_SHIFT;
455466 hole_start = (image->control_page + (size - 1)) & ~(size - 1);
456467 hole_end = hole_start + size - 1;
457− while(hole_end <= crashk_res.end) {
468+ while (hole_end <= crashk_res.end) {
458469 unsigned long i;
459− if (hole_end > KEXEC_CONTROL_MEMORY_LIMIT) {
470+
471+ if (hole_end > KEXEC_CONTROL_MEMORY_LIMIT)
460472 break;
461− }
462− if (hole_end > crashk_res.end) {
473+ if (hole_end > crashk_res.end)
463474 break;
464− }
465475 /* 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++) {
467477 unsigned long mstart, mend;
478+
468479 mstart = image->segment[i].mem;
469480 mend = mstart + image->segment[i].memsz - 1;
470481 if ((hole_end >= mstart) && (hole_start <= mend)) {
@@ -480,18 +491,19 @@ static struct page *kimage_alloc_crash_control_pages( · 9 unmodified lines
480491 break;
481492 }
482493 }
483− if (pages) {
494+ if (pages)
484495 image->control_page = hole_end;
485− }
496+
486497 return pages;
487498 }
488499
489500
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)
492503 {
493504 struct page *pages = NULL;
494− switch(image->type) {
505+
506+ switch (image->type) {
495507 case KEXEC_TYPE_DEFAULT:
496508 pages = kimage_alloc_normal_control_pages(image, order);
497509 break;
@@ -499,43 +511,46 @@ struct page *kimage_alloc_control_pages( · 1 unmodified line
499511 pages = kimage_alloc_crash_control_pages(image, order);
500512 break;
501513 }
514+
502515 return pages;
503516 }
504517
505518 static int kimage_add_entry(struct kimage *image, kimage_entry_t entry)
506519 {
507− if (*image->entry != 0) {
520+ if (*image->entry != 0)
508521 image->entry++;
509− }
522+
510523 if (image->entry == image->last_entry) {
511524 kimage_entry_t *ind_page;
512525 struct page *page;
526+
513527 page = kimage_alloc_page(image, GFP_KERNEL, KIMAGE_NO_DEST);
514− if (!page) {
528+ if (!page)
515529 return -ENOMEM;
516− }
530+
517531 ind_page = page_address(page);
518532 *image->entry = virt_to_phys(ind_page) | IND_INDIRECTION;
519533 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);
522536 }
523537 *image->entry = entry;
524538 image->entry++;
525539 *image->entry = 0;
540+
526541 return 0;
527542 }
528543
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)
531546 {
532547 int result;
533548
534549 destination &= PAGE_MASK;
535550 result = kimage_add_entry(image, destination | IND_DESTINATION);
536− if (result == 0) {
551+ if (result == 0)
537552 image->destination = destination;
538− }
553+
539554 return result;
540555 }
541556
@@ -546,9 +561,9 @@ static int kimage_add_page(struct kimage *image, unsigned long page) · 4 unmodified lines
546561
547562 page &= PAGE_MASK;
548563 result = kimage_add_entry(image, page | IND_SOURCE);
549− if (result == 0) {
564+ if (result == 0)
550565 image->destination += PAGE_SIZE;
551− }
566+
552567 return result;
553568 }
554569
@@ -564,10 +579,11 @@ static void kimage_free_extra_pages(struct kimage *image) · 9 unmodified lines
564579 }
565580 static int kimage_terminate(struct kimage *image)
566581 {
567− if (*image->entry != 0) {
582+ if (*image->entry != 0)
568583 image->entry++;
569− }
584+
570585 *image->entry = IND_DONE;
586+
571587 return 0;
572588 }
573589
@@ -591,26 +607,24 @@ static void kimage_free(struct kimage *image) · 17 unmodified lines
591607
592608 if (!image)
593609 return;
610+
594611 kimage_free_extra_pages(image);
595612 for_each_kimage_entry(image, ptr, entry) {
596613 if (entry & IND_INDIRECTION) {
597614 /* Free the previous indirection page */
598− if (ind & IND_INDIRECTION) {
615+ if (ind & IND_INDIRECTION)
599616 kimage_free_entry(ind);
600− }
601617 /* Save this indirection page until we are
602618 * done with it.
603619 */
604620 ind = entry;
605621 }
606− else if (entry & IND_SOURCE) {
622+ else if (entry & IND_SOURCE)
607623 kimage_free_entry(entry);
608− }
609624 }
610625 /* Free the final indirection page */
611− if (ind & IND_INDIRECTION) {
626+ if (ind & IND_INDIRECTION)
612627 kimage_free_entry(ind);
613− }
614628
615629 /* Handle any machine specific cleanup */
616630 machine_kexec_cleanup(image);
@@ -620,26 +634,28 @@ static void kimage_free(struct kimage *image) · 3 unmodified lines
620634 kfree(image);
621635 }
622636
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)
624639 {
625640 kimage_entry_t *ptr, entry;
626641 unsigned long destination = 0;
627642
628643 for_each_kimage_entry(image, ptr, entry) {
629− if (entry & IND_DESTINATION) {
644+ if (entry & IND_DESTINATION)
630645 destination = entry & PAGE_MASK;
631− }
632646 else if (entry & IND_SOURCE) {
633− if (page == destination) {
647+ if (page == destination)
634648 return ptr;
635− }
636649 destination += PAGE_SIZE;
637650 }
638651 }
652+
639653 return 0;
640654 }
641655
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)
643659 {
644660 /*
645661 * 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
679695
680696 /* Allocate a page, if we run out of memory give up */
681697 page = kimage_alloc_pages(gfp_mask, 0);
682− if (!page) {
698+ if (!page)
683699 return 0;
684− }
685700 /* 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)) {
687703 list_add(&page->lru, &image->unuseable_pages);
688704 continue;
689705 }
@@ -694,7 +710,8 @@ static struct page *kimage_alloc_page(struct kimage *image, unsigned int gfp_mas · 4 unmodified lines
694710 break;
695711
696712 /* 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))
698715 break;
699716
700717 /*
@@ -727,11 +744,12 @@ static struct page *kimage_alloc_page(struct kimage *image, unsigned int gfp_mas · 26 unmodified lines
727744 list_add(&page->lru, &image->dest_pages);
728745 }
729746 }
747+
730748 return page;
731749 }
732750
733751 static int kimage_load_normal_segment(struct kimage *image,
734− struct kexec_segment *segment)
752+ struct kexec_segment *segment)
735753 {
736754 unsigned long maddr;
737755 unsigned long ubytes, mbytes;
@@ -745,34 +763,36 @@ static int kimage_load_normal_segment(struct kimage *image, · 7 unmodified lines
745763 maddr = segment->mem;
746764
747765 result = kimage_set_destination(image, maddr);
748− if (result < 0) {
766+ if (result < 0)
749767 goto out;
750− }
751− while(mbytes) {
768+
769+ while (mbytes) {
752770 struct page *page;
753771 char *ptr;
754772 size_t uchunk, mchunk;
773+
755774 page = kimage_alloc_page(image, GFP_HIGHUSER, maddr);
756775 if (page == 0) {
757776 result = -ENOMEM;
758777 goto out;
759778 }
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)
762782 goto out;
763− }
783+
764784 ptr = kmap(page);
765785 /* Start with a clear page */
766786 memset(ptr, 0, PAGE_SIZE);
767787 ptr += maddr & ~PAGE_MASK;
768788 mchunk = PAGE_SIZE - (maddr & ~PAGE_MASK);
769− if (mchunk > mbytes) {
789+ if (mchunk > mbytes)
770790 mchunk = mbytes;
771− }
791+
772792 uchunk = mchunk;
773− if (uchunk > ubytes) {
793+ if (uchunk > ubytes)
774794 uchunk = ubytes;
775− }
795+
776796 result = copy_from_user(ptr, buf, uchunk);
777797 kunmap(page);
778798 if (result) {
@@ -784,12 +804,12 @@ static int kimage_load_normal_segment(struct kimage *image, · 5 unmodified lines
784804 buf += mchunk;
785805 mbytes -= mchunk;
786806 }
787− out:
807+out:
788808 return result;
789809 }
790810
791811 static int kimage_load_crash_segment(struct kimage *image,
792− struct kexec_segment *segment)
812+ struct kexec_segment *segment)
793813 {
794814 /* For crash dumps kernels we simply copy the data from
795815 * user space to it's destination.
@@ -805,10 +825,11 @@ static int kimage_load_crash_segment(struct kimage *image, · 9 unmodified lines
805825 ubytes = segment->bufsz;
806826 mbytes = segment->memsz;
807827 maddr = segment->mem;
808− while(mbytes) {
828+ while (mbytes) {
809829 struct page *page;
810830 char *ptr;
811831 size_t uchunk, mchunk;
832+
812833 page = pfn_to_page(maddr >> PAGE_SHIFT);
813834 if (page == 0) {
814835 result = -ENOMEM;
@@ -817,9 +838,9 @@ static int kimage_load_crash_segment(struct kimage *image, · 2 unmodified lines
817838 ptr = kmap(page);
818839 ptr += maddr & ~PAGE_MASK;
819840 mchunk = PAGE_SIZE - (maddr & ~PAGE_MASK);
820− if (mchunk > mbytes) {
841+ if (mchunk > mbytes)
821842 mchunk = mbytes;
822− }
843+
823844 uchunk = mchunk;
824845 if (uchunk > ubytes) {
825846 uchunk = ubytes;
@@ -837,15 +858,16 @@ static int kimage_load_crash_segment(struct kimage *image, · 11 unmodified lines
837858 buf += mchunk;
838859 mbytes -= mchunk;
839860 }
840− out:
861+out:
841862 return result;
842863 }
843864
844865 static int kimage_load_segment(struct kimage *image,
845− struct kexec_segment *segment)
866+ struct kexec_segment *segment)
846867 {
847868 int result = -ENOMEM;
848− switch(image->type) {
869+
870+ switch (image->type) {
849871 case KEXEC_TYPE_DEFAULT:
850872 result = kimage_load_normal_segment(image, segment);
851873 break;
@@ -853,6 +875,7 @@ static int kimage_load_segment(struct kimage *image, · 1 unmodified line
853875 result = kimage_load_crash_segment(image, segment);
854876 break;
855877 }
878+
856879 return result;
857880 }
858881
@@ -885,9 +908,9 @@ static struct kimage *kexec_crash_image = NULL; · 26 unmodified lines
885908 */
886909 static int kexec_lock = 0;
887910
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)
891914 {
892915 struct kimage **dest_image, *image;
893916 int locked;
@@ -907,9 +930,7 @@ asmlinkage long sys_kexec_load(unsigned long entry, · 13 unmodified lines
907930 /* Verify we are on the appropriate architecture */
908931 if (((flags & KEXEC_ARCH_MASK) != KEXEC_ARCH) &&
909932 ((flags & KEXEC_ARCH_MASK) != KEXEC_ARCH_DEFAULT))
910− {
911933 return -EINVAL;
912− }
913934
914935 /* Put an artificial cap on the number
915936 * of segments passed to kexec_load.
@@ -929,58 +950,59 @@ asmlinkage long sys_kexec_load(unsigned long entry, · 13 unmodified lines
929950 * KISS: always take the mutex.
930951 */
931952 locked = xchg(&kexec_lock, 1);
932− if (locked) {
953+ if (locked)
933954 return -EBUSY;
934− }
955+
935956 dest_image = &kexec_image;
936− if (flags & KEXEC_ON_CRASH) {
957+ if (flags & KEXEC_ON_CRASH)
937958 dest_image = &kexec_crash_image;
938− }
939959 if (nr_segments > 0) {
940960 unsigned long i;
961+
941962 /* 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);
945966 /* Loading another kernel to switch to if this one crashes */
946967 else if (flags & KEXEC_ON_CRASH) {
947968 /* Free any current crash dump kernel before
948969 * we corrupt it.
949970 */
950971 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);
952974 }
953− if (result) {
975+ if (result)
954976 goto out;
955− }
977+
956978 result = machine_kexec_prepare(image);
957− if (result) {
979+ if (result)
958980 goto out;
959− }
960− for(i = 0; i < nr_segments; i++) {
981+
982+ for (i = 0; i < nr_segments; i++) {
961983 result = kimage_load_segment(image, &image->segment[i]);
962− if (result) {
984+ if (result)
963985 goto out;
964− }
965986 }
966987 result = kimage_terminate(image);
967− if (result) {
988+ if (result)
968989 goto out;
969− }
970990 }
971991 /* Install the new kernel, and Uninstall the old */
972992 image = xchg(dest_image, image);
973993
974− out:
994+out:
975995 xchg(&kexec_lock, 0); /* Release the mutex */
976996 kimage_free(image);
997+
977998 return result;
978999 }
9791000
9801001 #ifdef CONFIG_COMPAT
9811002 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)
9841006 {
9851007 struct compat_kexec_segment in;
9861008 struct kexec_segment out, __user *ksegments;
@@ -989,20 +1011,17 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry, · 2 unmodified lines
9891011 /* Don't allow clients that don't understand the native
9901012 * architecture to do anything.
9911013 */
992− if ((flags & KEXEC_ARCH_MASK) == KEXEC_ARCH_DEFAULT) {
1014+ if ((flags & KEXEC_ARCH_MASK) == KEXEC_ARCH_DEFAULT)
9931015 return -EINVAL;
994− }
9951016
996− if (nr_segments > KEXEC_SEGMENT_MAX) {
1017+ if (nr_segments > KEXEC_SEGMENT_MAX)
9971018 return -EINVAL;
998− }
9991019
10001020 ksegments = compat_alloc_user_space(nr_segments * sizeof(out));
10011021 for (i=0; i < nr_segments; i++) {
10021022 result = copy_from_user(&in, &segments[i], sizeof(in));
1003− if (result) {
1023+ if (result)
10041024 return -EFAULT;
1005− }
10061025
10071026 out.buf = compat_ptr(in.buf);
10081027 out.bufsz = in.bufsz;
@@ -1010,9 +1029,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry, · 1 unmodified line
10101029 out.memsz = in.memsz;
10111030
10121031 result = copy_to_user(&ksegments[i], &out, sizeof(out));
1013− if (result) {
1032+ if (result)
10141033 return -EFAULT;
1015− }
10161034 }
10171035
10181036 return sys_kexec_load(entry, nr_segments, ksegments, flags);