User Tools

Site Tools


Linux Kernel Programming

Special Topics

  • Suppress scheduling by use of preempt_disable(), see preempt-locking.txt for other methods.
  • For use of [num]delay(), usleep() and friends see timers-howto.txt.
  • Use WARN_ON() and BUG_ON() macros for run-time assertions.
  • Functions irqs_disabled() and in_interrupt() are very helpful regarding protection of non-preemptive code (see also the comments at Stack Overflow).
  • MII ioctl of a network device, called from within kernel code:
    const struct net_device_ops *ops = ndev->netdev_ops;
    int err = -ENXIO;
    if (ops->ndo_do_ioctl) {
    	struct ifreq ifr;
    	struct mii_ioctl_data mii;
    	mm_segment_t oldfs = get_fs();
    	mii.reg_num = MII_BMCR;
    	ifr.ifr_ifru.ifru_data = (__force void __user *)&mii;
    	err = ops->ndo_do_ioctl(ndev, &ifr, SIOCGMIIPHY);
    	if (!err) {
    		mii.val_in = (mii.val_out & ~BMCR_RESET) | BMCR_ISOLATE;
    		err = ops->ndo_do_ioctl(ndev, &ifr, SIOCSMIIREG);
    		netdev_dbg(ndev, "%s: MII ioctl setting BMCR = 0x%04x\n",
    			__func__, mii.val_in);
programming/linux.txt · Last modified: 2018/05/09 07:09 by Ralf Hoppe