Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8779193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:43:27+00:00 2026-06-13T19:43:27+00:00

is it required to unlock net_device structure before calling free_netdev? The code I encountered

  • 0

is it required to unlock net_device structure before calling free_netdev? The code I encountered does the following:

static void delete_dev(struct net_device *dev)
{
   ASSERT_RTNL();
   ...
   unregister_netdevice(dev);
   ...
   rtnl_unlock();
   free_netdev(dev);
   rtnl_lock();
}

int foo()
{
   struct net_device *dev;

   rtnl_lock();
   ...
   delete_dev(dev);
   rtnl_unlock();
   return 0;
}

Is this the right way to do the things? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:43:29+00:00Added an answer on June 13, 2026 at 7:43 pm

    You should not unlock-lock rtnl one more time.

    Here is why: there is not a word in Network Drivers API in free_netdev section about lock required. Nevertheless, unregister_netdevice requires lock to be held and it has been wrapped in API in unregister_netdev function, which is stated in the document.

    Anyway, if you look into some popular driver’s sources, e1000e for example, you will see this:

    6432 static void __devexit e1000_remove(struct pci_dev *pdev)
    6433 {
    ...
    6459         unregister_netdev(netdev);
    6460 
    6461         if (pci_dev_run_wake(pdev))
    6462                 pm_runtime_get_noresume(&pdev->dev);
    6463 
    6464         /*
    6465          * Release control of h/w to f/w.  If f/w is AMT enabled, this
    6466          * would have already happened in close and is redundant.
    6467          */
    6468         e1000e_release_hw_control(adapter);
    6469 
    6470         e1000e_reset_interrupt_capability(adapter);
    6471         kfree(adapter->tx_ring);
    6472         kfree(adapter->rx_ring);
    6473 
    6474         iounmap(adapter->hw.hw_addr);
    6475         if (adapter->hw.flash_address)
    6476                 iounmap(adapter->hw.flash_address);
    6477         pci_release_selected_regions(pdev,
    6478                                      pci_select_bars(pdev, IORESOURCE_MEM));
    6479 
    6480         free_netdev(netdev);
    6481 
    6482         /* AER disable */
    6483         pci_disable_pcie_error_reporting(pdev);
    6484 
    6485         pci_disable_device(pdev);
    6486 }
    

    As you can see, there is no unlock-lock taken.

    Moreover, they use unregister_netdev function so that it would only be locked inside unregister_netdevice itself, and all dozens of deinitialinizations there would go outside the lock. Therefore, consider using simple unregister_netdev as they(netdev kernel developers) recommend in comments to it’s source, if you think you can afford that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code required to append list (anotherList) to item (id -= l1) of second list
Assume that the following code is being executed by 10 threads. pthread_mutex_lock(&lock) Some trivial
The C++11 standard defines unique_lock::unlock as (§ 30.4.2.2.2, p. 1159) void unlock(); Effects: pm->unlock()
required( dependency-expression ) They give an example of required: #other:checked but I want my
Advice required on architecting module I have a PORT Listener that listens to a
I am required to write a C++ application to run on an embedded Linux
We use @Constraint.Required to validate the fields of our forms, and this generates a
// No overrides required .. let CLR take care of equal and hashcode. Class
What is the NSFormat required for a string like this? Fri, 15 Jun 2012
I am required to count all the instances of quotes in the system based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.