aboutsummaryrefslogtreecommitdiff
path: root/util-linux/mdev.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux/mdev.c')
-rw-r--r--util-linux/mdev.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 0a34122b4..c4829a596 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -661,37 +661,45 @@ static int FAST_FUNC dirAction(const char *fileName UNUSED_PARAM,
661static void load_firmware(const char *firmware, const char *sysfs_path) 661static void load_firmware(const char *firmware, const char *sysfs_path)
662{ 662{
663 int cnt; 663 int cnt;
664 int firmware_fd, loading_fd, data_fd; 664 int firmware_fd, loading_fd;
665 665
666 /* check for /lib/firmware/$FIRMWARE */ 666 /* check for /lib/firmware/$FIRMWARE */
667 xchdir("/lib/firmware"); 667 xchdir("/lib/firmware");
668 firmware_fd = xopen(firmware, O_RDONLY); 668 firmware_fd = open(firmware, O_RDONLY); /* can fail */
669
670 /* in case we goto out ... */
671 data_fd = -1;
672 669
673 /* check for /sys/$DEVPATH/loading ... give 30 seconds to appear */ 670 /* check for /sys/$DEVPATH/loading ... give 30 seconds to appear */
674 xchdir(sysfs_path); 671 xchdir(sysfs_path);
675 for (cnt = 0; cnt < 30; ++cnt) { 672 for (cnt = 0; cnt < 30; ++cnt) {
676 loading_fd = open("loading", O_WRONLY); 673 loading_fd = open("loading", O_WRONLY);
677 if (loading_fd != -1) 674 if (loading_fd >= 0)
678 goto loading; 675 goto loading;
679 sleep(1); 676 sleep(1);
680 } 677 }
681 goto out; 678 goto out;
682 679
683 loading: 680 loading:
684 /* tell kernel we're loading by "echo 1 > /sys/$DEVPATH/loading" */ 681 cnt = 0;
685 if (full_write(loading_fd, "1", 1) != 1) 682 if (firmware_fd >= 0) {
686 goto out; 683 int data_fd;
687 684
688 /* load firmware into /sys/$DEVPATH/data */ 685 /* tell kernel we're loading by "echo 1 > /sys/$DEVPATH/loading" */
689 data_fd = open("data", O_WRONLY); 686 if (full_write(loading_fd, "1", 1) != 1)
690 if (data_fd == -1) 687 goto out;
691 goto out; 688
692 cnt = bb_copyfd_eof(firmware_fd, data_fd); 689 /* load firmware into /sys/$DEVPATH/data */
690 data_fd = open("data", O_WRONLY);
691 if (data_fd < 0)
692 goto out;
693 cnt = bb_copyfd_eof(firmware_fd, data_fd);
694 if (ENABLE_FEATURE_CLEAN_UP)
695 close(data_fd);
696 }
693 697
694 /* tell kernel result by "echo [0|-1] > /sys/$DEVPATH/loading" */ 698 /* Tell kernel result by "echo [0|-1] > /sys/$DEVPATH/loading"
699 * Note: we emit -1 if firmware file wasn't found.
700 * There are cases when otherwise kernel would wait for minutes
701 * before timing out.
702 */
695 if (cnt > 0) 703 if (cnt > 0)
696 full_write(loading_fd, "0", 1); 704 full_write(loading_fd, "0", 1);
697 else 705 else
@@ -701,7 +709,6 @@ static void load_firmware(const char *firmware, const char *sysfs_path)
701 if (ENABLE_FEATURE_CLEAN_UP) { 709 if (ENABLE_FEATURE_CLEAN_UP) {
702 close(firmware_fd); 710 close(firmware_fd);
703 close(loading_fd); 711 close(loading_fd);
704 close(data_fd);
705 } 712 }
706} 713}
707 714