From nobody@FreeBSD.org  Thu Sep 20 05:26:04 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 2D0E137B41E
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 20 Sep 2001 05:26:04 -0700 (PDT)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.4/8.11.4) id f8KCQ4J67002;
	Thu, 20 Sep 2001 05:26:04 -0700 (PDT)
	(envelope-from nobody)
Message-Id: <200109201226.f8KCQ4J67002@freefall.freebsd.org>
Date: Thu, 20 Sep 2001 05:26:04 -0700 (PDT)
From: HARASHINO Makoto <harashi@jazz.email.ne.jp>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] loader(8) fails to load module which has dependencies
X-Send-Pr-Version: www-1.0

>Number:         30683
>Category:       misc
>Synopsis:       [PATCH] loader(8) fails to load module which has dependencies
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 20 05:30:01 PDT 2001
>Closed-Date:    Thu Dec 19 04:44:50 PST 2002
>Last-Modified:  Thu Dec 19 04:44:50 PST 2002
>Originator:     HARASHINO Makoto
>Release:        
>Organization:
>Environment:
4.4-RC FreeBSD 4.4-RC #0: Tue Sep 18 11:02:56 JST 2001
>Description:
When loader(8) try to load module which has dependencies
if the dependencies already loaded, invalidate the whole.

>How-To-Repeat:
try this in the /boot/loader command line

    load miibus
    load if_xl

or

    load snd_pcm
    load snd_ds1

and so on.

>Fix:
Apply patch included below.

diff -ru boot.orig/common/module.c boot/common/module.c
--- boot.orig/common/module.c	Wed Jun 13 03:10:35 2001
+++ boot/common/module.c	Thu Sep 20 09:24:37 2001
@@ -365,12 +365,20 @@
 	return (0);
     error = 0;
     do {
+	char* tmp;
 	dmodname = (char *)md->md_data;
-	if (mod_findmodule(NULL, dmodname) == NULL) {
+	tmp = malloc(strlen(dmodname) + 3 + 1);
+	strcpy(tmp, dmodname);
+	strcat(tmp, ".ko");
+	if (mod_findmodule(tmp, NULL) == NULL) {
+	    free(tmp);
 	    printf("loading required module '%s'\n", dmodname);
 	    error = mod_load(dmodname, 0, NULL);
 	    if (error && error != EEXIST)
 		break;
+	    error = 0;
+	} else {
+	    free(tmp);
 	}
 	md = metadata_next(md, MODINFOMD_DEPLIST);
     } while (md);

>Release-Note:
>Audit-Trail:

From: Tadaaki Nagao <tada@rr.iij4u.or.jp>
To: freebsd-gnats-submit@FreeBSD.org, harashi@jazz.email.ne.jp
Cc:  
Subject: Re: misc/30683: [PATCH] loader(8) fails to load module which has
 dependencies
Date: Sun, 19 May 2002 04:23:17 +0900 (JST)

 Hi,
 
 (I'm writing this mail in the hope of attracting committer's
 interest to this PR misc/30683...)
 
 I suffered from a loader(8) problem in RELENG_4 and fixed it myself,
 not having realized that the problem has been already filed as a PR
 by Harashino-san.
 
 My fix is similar to Harashino-san's, but it looks simpler, as
 attached below.
 
 Index: module.c
 ===================================================================
 RCS file: /usr/ncvs/src/sys/boot/common/module.c,v
 retrieving revision 1.13.2.3
 diff -u -r1.13.2.3 module.c
 --- module.c	12 Jun 2001 15:35:14 -0000	1.13.2.3
 +++ module.c	13 Mar 2002 03:08:03 -0000
 @@ -363,18 +363,17 @@
      md = mod_findmetadata(base_file, MODINFOMD_DEPLIST);
      if (md == NULL)
  	return (0);
 -    error = 0;
      do {
  	dmodname = (char *)md->md_data;
  	if (mod_findmodule(NULL, dmodname) == NULL) {
  	    printf("loading required module '%s'\n", dmodname);
  	    error = mod_load(dmodname, 0, NULL);
  	    if (error && error != EEXIST)
 -		break;
 +		return (error);
  	}
  	md = metadata_next(md, MODINFOMD_DEPLIST);
      } while (md);
 -    return (error);
 +    return (0);
  }
  
  /*
 
 
 While Harashino-san's patch in PR misc/30683 also modifies what string
 will be passed to mod_findmodule() by strcat'ing dmodname with ".ko",
 I don't see why this is needed. Perhaps there might be something I'm
 overlooking.
 
 I'd appreciate it if someone would give any comments to my patch
 above and/or point me to any information I'm overlooking.
 
 Thanks,
 Tadaaki Nagao <tada@rr.iij4u.or.jp>
State-Changed-From-To: open->closed 
State-Changed-By: thomas 
State-Changed-When: Thu Dec 19 04:43:40 PST 2002 
State-Changed-Why:  
A slightly different fix was committed as sys/boot/common/module.c 
rev. 1.13.2.4. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=30683 
>Unformatted:
