Ticket #203: imr-renaming-patch-r2.diff

File imr-renaming-patch-r2.diff, 13.1 kB (added by imr1@waikato.ac.nz, 6 years ago)

Same as imr-kickmac-patch.diff, but this returns any error code.

  • net80211/ieee80211_linux.c

    old new  
    579579{ 
    580580        int i, space; 
    581581 
     582        char *devname = NULL; 
    582583        space = 5*sizeof(struct ctl_table) + sizeof(ieee80211_sysctl_template); 
    583584        vap->iv_sysctls = kmalloc(space, GFP_KERNEL); 
    584585        if (vap->iv_sysctls == NULL) { 
     
    586587                return; 
    587588        } 
    588589 
     590        /* Reserve space for the device name outside the net_device structure 
     591         * so that if the name changes we know what it used to be.  
     592         */ 
     593        devname = kmalloc((strlen(vap->iv_dev->name) + 1) * sizeof(char), GFP_KERNEL); 
     594        if(devname == NULL) { 
     595                printk("%s: no memory for VAP name!\n", __func__); 
     596                return; 
     597        } 
     598        strncpy(devname, vap->iv_dev->name, strlen(vap->iv_dev->name) + 1); 
    589599        /* setup the table */ 
    590600        memset(vap->iv_sysctls, 0, space); 
    591601        vap->iv_sysctls[0].ctl_name = CTL_NET; 
     
    594604        vap->iv_sysctls[0].child = &vap->iv_sysctls[2]; 
    595605        /* [1] is NULL terminator */ 
    596606        vap->iv_sysctls[2].ctl_name = CTL_AUTO; 
    597         vap->iv_sysctls[2].procname = vap->iv_dev->name;/* XXX bad idea? */ 
     607        vap->iv_sysctls[2].procname = devname;//vap->iv_dev->name;/* XXX bad idea? */ 
    598608        vap->iv_sysctls[2].mode = 0555; 
    599609        vap->iv_sysctls[2].child = &vap->iv_sysctls[4]; 
    600610        /* [3] is NULL terminator */ 
     
    630640 
    631641        if (proc_madwifi) { 
    632642                proc_madwifi_count++; 
    633                 vap->iv_proc = proc_mkdir(vap->iv_dev->name, proc_madwifi); 
     643                vap->iv_proc = proc_mkdir(devname, proc_madwifi); 
    634644                if (vap->iv_proc) { 
    635645                        vap->iv_proc_stations = create_proc_entry("associated_sta", 
    636646                                                                  PROC_IEEE80211_PERM, vap->iv_proc); 
     
    640650        } 
    641651 
    642652} 
     653EXPORT_SYMBOL(ieee80211_sysctl_vattach); 
    643654 
    644655void 
    645656ieee80211_sysctl_vdetach(struct ieee80211vap *vap) 
     
    648659                unregister_sysctl_table(vap->iv_sysctl_header); 
    649660                vap->iv_sysctl_header = NULL; 
    650661        } 
    651         if (vap->iv_sysctls) { 
    652                 kfree(vap->iv_sysctls); 
    653                 vap->iv_sysctls = NULL; 
    654         } 
    655  
     662         
    656663        if (vap->iv_proc) { 
    657664                remove_proc_entry("associated_sta", vap->iv_proc); 
    658                 remove_proc_entry(vap->iv_dev->name, proc_madwifi); 
     665                remove_proc_entry(vap->iv_sysctls[2].procname, proc_madwifi); 
    659666                if (proc_madwifi_count == 1) { 
    660667                        remove_proc_entry("madwifi", proc_net); 
    661                         proc_madwifi = NULL; 
     668                       proc_madwifi = NULL; 
    662669                } 
    663                 proc_madwifi_count--; 
     670               proc_madwifi_count--; 
    664671        } 
    665672 
     673        if(vap->iv_sysctls[2].procname) { 
     674                kfree(vap->iv_sysctls[2].procname); 
     675                vap->iv_sysctls[2].procname = NULL; 
     676        } 
     677         
     678        if (vap->iv_sysctls) { 
     679                kfree(vap->iv_sysctls); 
     680                vap->iv_sysctls = NULL; 
     681        } 
     682 
    666683} 
     684EXPORT_SYMBOL(ieee80211_sysctl_vdetach); 
    667685#endif /* CONFIG_SYSCTL */ 
    668686 
    669687/* 
  • ath/if_ath_ahb.c

    old new  
    421421MODULE_LICENSE("Dual BSD/GPL"); 
    422422#endif 
    423423 
     424static struct notifier_block ath_dev_notifier = { 
     425        .notifier_call = ath_rcv_dev_event, 
     426}; 
     427 
    424428static int __init 
    425429init_ath_ahb(void) 
    426430{ 
    427431        printk(KERN_INFO "%s: %s\n", dev_info, version); 
    428432 
     433        /* Initialise the interface list so we can record 
     434         * which devices we need to maintain proc entries for. 
     435         */ 
     436        ath_initialise_interface_list(); 
    429437        if (init_ahb() != 0) { 
    430438                printk("ath_ahb: No devices found, driver not installed.\n"); 
    431439                return (-ENODEV); 
     
    433441#ifdef CONFIG_SYSCTL 
    434442        ath_sysctl_register(); 
    435443#endif 
     444 
     445        /* Register for netdevice events so we can maintain 
     446         * the proc entries when interface names change. 
     447         */ 
     448        register_netdevice_notifier(&ath_dev_notifier); 
    436449        return (0); 
    437450} 
    438451module_init(init_ath_ahb); 
     
    440453static void __exit 
    441454exit_ath_ahb(void) 
    442455{ 
     456        /* We're unloading, so we need to unregister our interest 
     457         * in netdevice notifications. 
     458         */ 
     459        unregister_netdevice_notifier(&ath_dev_notifier); 
    443460#ifdef CONFIG_SYSCTL 
    444461        ath_sysctl_unregister(); 
    445462#endif 
    446463        exit_ath_wmac(AR531X_WLAN0_NUM); 
    447464        exit_ath_wmac(AR531X_WLAN1_NUM); 
    448465 
     466        /* The list will no longer be being modified, so we 
     467         * can clean it up and remove any memory that is still 
     468         * being used by it. 
     469         */ 
     470        ath_cleanup_interface_list(); 
     471         
    449472        printk(KERN_INFO "%s: driver unloaded\n", dev_info); 
    450473} 
    451474module_exit(exit_ath_ahb); 
  • ath/if_ath_pci.c

    old new  
    320320#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,22) 
    321321        /* include the device name so later versions of kudzu DTRT */ 
    322322        strncpy(info.bus_info, pci_name((struct pci_dev *)sc->sc_bdev), 
    323                sizeof(info.bus_info)-1); 
     323sizeof(info.bus_info)-1); 
    324324#endif 
    325325        return copy_to_user(addr, &info, sizeof(info)) ? -EFAULT : 0; 
    326326} 
     
    332332MODULE_LICENSE("Dual BSD/GPL"); 
    333333#endif 
    334334 
     335static struct notifier_block ath_dev_notifier = { 
     336        .notifier_call = ath_rcv_dev_event, 
     337}; 
     338 
    335339static int __init 
    336340init_ath_pci(void) 
    337341{ 
    338342        printk(KERN_INFO "%s: %s\n", dev_info, version); 
    339343 
     344        /* Setup the list of interfaces that interest us 
     345         * so they can be recorded when they are created. 
     346         */ 
     347        ath_initialise_interface_list(); 
     348         
    340349        if (pci_register_driver(&ath_pci_drv_id) < 0) { 
    341350                printk("ath_pci: No devices found, driver not installed.\n"); 
    342351                pci_unregister_driver(&ath_pci_drv_id); 
    343352                return (-ENODEV); 
    344353        } 
     354 
     355        /* Register for netdevice notifications so we can maintain 
     356         * the proc entries correctly. 
     357         */ 
     358        register_netdevice_notifier(&ath_dev_notifier); 
    345359#ifdef CONFIG_SYSCTL 
    346360        ath_sysctl_register(); 
    347361#endif 
     
    355369#ifdef CONFIG_SYSCTL 
    356370        ath_sysctl_unregister(); 
    357371#endif 
     372        /* The module is unloading, so we need to unregister our 
     373         * interest in netdevice notifications. 
     374         */ 
     375        unregister_netdevice_notifier(&ath_dev_notifier); 
    358376        pci_unregister_driver(&ath_pci_drv_id); 
    359377 
     378        /* The interfaces list will no longer be modified, so  
     379         * clean up any memory used by it. 
     380         */ 
     381        ath_cleanup_interface_list(); 
    360382        printk(KERN_INFO "%s: driver unloaded\n", dev_info); 
    361383} 
    362384module_exit(exit_ath_pci); 
  • ath/if_athvar.h

    old new  
    664664void    ath_sysctl_unregister(void); 
    665665#endif /* CONFIG_SYSCTL */ 
    666666 
     667/* Device Event Notification */ 
     668int ath_rcv_dev_event(struct notifier_block *, unsigned long, void *); 
     669 
     670/* Interface List preperatation */ 
     671struct ath_interfaces_list { 
     672        struct list_head list; 
     673        struct net_device *dev; 
     674        unsigned char type; 
     675}; 
     676 
     677void ath_initialise_interface_list(void); 
     678void ath_cleanup_interface_list(void); 
     679 
    667680/* 
    668681 * HAL definitions to comply with local coding convention. 
    669682 */ 
  • ath/if_ath.c

    old new  
    6868#include <net80211/ieee80211_var.h> 
    6969#include <net80211/ieee80211_monitor.h> 
    7070 
     71#include <net80211/ieee80211_linux.h> 
     72 
    7173#ifdef USE_HEADERLEN_RESV 
    7274#include <net80211/if_llc.h> 
    7375#endif 
     
    381383        }                                   \ 
    382384    } while(0) 
    383385 
     386struct ath_interfaces_list interface_list; 
     387 
     388/* 
     389 * Initialises the list of interfaces to watch for when 
     390 * we recieve device notifier events. 
     391 */ 
     392 
     393void ath_initialise_interface_list() 
     394{ 
     395        INIT_LIST_HEAD(&interface_list.list); 
     396} 
     397 
     398 
     399/* 
     400 * Goes through the interface list deleting all entries and 
     401 * freeing any memory allocated to them. 
     402 * Done when the module is being unloaded. 
     403 */ 
     404void ath_cleanup_interface_list() 
     405{ 
     406        struct list_head *pos, *q; 
     407        struct ath_interfaces_list *tmp; 
     408         
     409        list_for_each_safe(pos, q, &(interface_list.list)) { 
     410                tmp = list_entry(pos, struct ath_interfaces_list, list); 
     411                list_del(pos); 
     412                kfree(tmp); 
     413        } 
     414} 
     415 
     416/* Function to handle the device event notifications. 
     417 * If the event is a NETDEV_CHANGENAME, and is for an interface 
     418 * we are taking care of, then we want to remove it's existing  
     419 * proc entries (which now have the wrong names) and add 
     420 * new, correct, entries. 
     421 */ 
    384422int 
     423ath_rcv_dev_event(struct notifier_block *this, unsigned long event, 
     424                void *ptr) 
     425{ 
     426        struct net_device *dev = ptr; 
     427        struct ath_interfaces_list *tmp = NULL; 
     428 
     429#ifdef CONFIG_SYSCTL 
     430        switch (event) { 
     431                case NETDEV_CHANGE: 
     432                        break; 
     433                case NETDEV_CHANGENAME: 
     434                        /* In here, we want to register and deregister 
     435                         * the sysctls, effectively moving 
     436                         * the proc entries to the correct place. 
     437                         */ 
     438                        list_for_each_entry(tmp, &interface_list.list, list) { 
     439                                /* If this is a device in our list of 
     440                                 * devices to watch for:  
     441                                 */ 
     442                                if(tmp->dev != dev)  
     443                                        break; 
     444                                 
     445                                /* If the type is 0, then it 
     446                                 * a base interface (typically wifi%d) 
     447                                 * then we handle it with one 
     448                                 * set of functions 
     449                                 */ 
     450                                if(tmp->type == 0) { 
     451                                        ath_dynamic_sysctl_unregister( 
     452                                                        dev->priv); 
     453                                        ath_dynamic_sysctl_register( 
     454                                                        dev->priv); 
     455                                } 
     456                                /* If the type is 1 it's a VAP 
     457                                 * and so we use a different set. 
     458                                 */ 
     459                                else if(tmp->type == 1) { 
     460                                        ieee80211_sysctl_vdetach(dev->priv); 
     461                                        ieee80211_sysctl_vattach(dev->priv); 
     462                                } 
     463                        } 
     464                        break; 
     465        } 
     466#endif /* CONFIG_SYSCTL */ 
     467        return NOTIFY_DONE; 
     468} 
     469 
     470 
     471 
     472int 
    385473ath_attach(u_int16_t devid, struct net_device *dev) 
    386474{ 
    387475        struct ath_softc *sc = dev->priv; 
     
    391479        int error = 0,i; 
    392480        u_int8_t csz; 
    393481 
     482        struct ath_interfaces_list *tmp = NULL; 
     483         
    394484        sc->sc_debug = ath_debug; 
    395485        DPRINTF(sc, ATH_DEBUG_ANY, "%s: devid 0x%x\n", __func__, devid); 
    396486 
     
    853943                printk(KERN_ERR "%s: unable to register device\n", dev->name); 
    854944                goto bad3; 
    855945        } 
     946 
     947        /* interfaces list is definately setup now, so add the new 
     948         * device to the list. */ 
     949 
     950        tmp = (struct ath_interfaces_list *)kmalloc( 
     951                        sizeof(struct ath_interfaces_list), GFP_KERNEL); 
     952        if(tmp == NULL) { 
     953                printk(KERN_ERR "%s: unable to allocate space for interface list\n" 
     954                                , dev->name); 
     955                goto bad3; 
     956        } 
     957        tmp->dev = dev; 
     958        tmp->type = 0; 
     959        list_add(&(tmp->list), &(interface_list.list)); 
    856960        /* 
    857961         * Attach dynamic MIB vars and announce support 
    858962         * now that we have a device name with unit number. 
     
    888992        struct ath_softc *sc = dev->priv; 
    889993        struct ath_hal *ah = sc->sc_ah; 
    890994 
     995         
    891996        DPRINTF(sc, ATH_DEBUG_ANY, "%s: flags %x\n", __func__, dev->flags); 
    892997        ath_stop(dev); 
    893998 
     
    9391044        struct ieee80211vap *vap; 
    9401045        int ic_opmode; 
    9411046 
     1047        struct ath_interfaces_list *tmp = NULL; 
     1048         
    9421049        /* XXX ic unlocked and race against add */ 
    9431050        switch (opmode) { 
    9441051        case IEEE80211_M_STA:   /* ap+sta for repeater application */ 
     
    9921099        } 
    9931100        avp = dev->priv; 
    9941101        ieee80211_vap_setup(ic, dev, name, unit, opmode, flags); 
     1102        tmp = (struct ath_interfaces_list *)kmalloc( 
     1103                        sizeof(struct ath_interfaces_list), GFP_KERNEL); 
     1104        if(tmp == NULL) { 
     1105                return NULL; 
     1106        } 
     1107        tmp->dev = dev; 
     1108        tmp->type = 1; 
     1109        list_add(&(tmp->list), &(interface_list.list)); 
    9951110        /* override with driver methods */ 
    9961111        vap = &avp->av_vap; 
    9971112        avp->av_newstate = vap->iv_newstate; 
     
    11381253        struct ath_hal *ah = sc->sc_ah; 
    11391254        struct ath_vap *avp = ATH_VAP(vap); 
    11401255        int decrease = 1; 
     1256 
     1257 
     1258        struct ath_interfaces_list *tmp = NULL; 
     1259        struct list_head *pos, *q; 
    11411260        KASSERT(vap->iv_state == IEEE80211_S_INIT, ("vap not stopped")); 
    11421261 
    11431262        if (dev->flags & IFF_RUNNING) { 
     
    11841303                decrease = 0; 
    11851304        } 
    11861305        ieee80211_vap_detach(vap); 
     1306        list_for_each_safe(pos,q,&(interface_list.list)) { 
     1307                tmp= list_entry(pos, struct ath_interfaces_list, list); 
     1308                if(tmp->dev == dev) { 
     1309                        list_del(pos); 
     1310                        kfree(tmp); 
     1311                } 
     1312        } 
    11871313        /* NB: memory is reclaimed through dev->destructor callback */ 
    11881314        if (decrease) 
    11891315                sc->sc_nvaps--; 
     
    92189344{ 
    92199345        int i, space; 
    92209346 
     9347        /* Space for the dev->name */ 
     9348        char *dev_name = NULL; 
    92219349        space = 5*sizeof(struct ctl_table) + sizeof(ath_sysctl_template); 
    92229350        sc->sc_sysctls = kmalloc(space, GFP_KERNEL); 
    92239351        if (sc->sc_sysctls == NULL) { 
     
    92259353                return; 
    92269354        } 
    92279355 
     9356        /* We want to reserve space for the name of the device seperate 
     9357         * to the net_device structure, because when the name is changed 
     9358         * it is changed in the net_device structure and the message given 
     9359         * out.  Thus we won't know what the name used to be if we rely 
     9360         * on it. 
     9361         */ 
     9362        dev_name = kmalloc((strlen(sc->sc_dev->name) + 1) * sizeof(char), GFP_KERNEL); 
     9363        if (dev_name == NULL) { 
     9364                printk("%s: no memory for device name storage!\n", __func__); 
     9365                return; 
     9366        } 
     9367        strncpy(dev_name, sc->sc_dev->name, strlen(sc->sc_dev->name) + 1); 
    92289368        /* setup the table */ 
    92299369        memset(sc->sc_sysctls, 0, space); 
    92309370        sc->sc_sysctls[0].ctl_name = CTL_DEV; 
     
    92339373        sc->sc_sysctls[0].child = &sc->sc_sysctls[2]; 
    92349374        /* [1] is NULL terminator */ 
    92359375        sc->sc_sysctls[2].ctl_name = CTL_AUTO; 
    9236         sc->sc_sysctls[2].procname = sc->sc_dev->name; 
     9376        sc->sc_sysctls[2].procname = dev_name; 
    92379377        sc->sc_sysctls[2].mode = 0555; 
    92389378        sc->sc_sysctls[2].child = &sc->sc_sysctls[4]; 
    92399379        /* [3] is NULL terminator */ 
     
    92679407                unregister_sysctl_table(sc->sc_sysctl_header); 
    92689408                sc->sc_sysctl_header = NULL; 
    92699409        } 
     9410        if(sc->sc_sysctls[2].procname) { 
     9411                kfree(sc->sc_sysctls[2].procname); 
     9412                sc->sc_sysctls[2].procname = NULL; 
     9413        } 
    92709414        if (sc->sc_sysctls) { 
    92719415                kfree(sc->sc_sysctls); 
    92729416                sc->sc_sysctls = NULL;