From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46997C433DB for ; Wed, 17 Mar 2021 15:59:29 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B32A764E61 for ; Wed, 17 Mar 2021 15:59:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B32A764E61 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kroah.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94) (envelope-from ) id 1lMYZp-0007vR-PF; Wed, 17 Mar 2021 11:59:17 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lMYZn-0007us-5v for kernelnewbies@kernelnewbies.org; Wed, 17 Mar 2021 11:59:15 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 236D25C0108 for ; Wed, 17 Mar 2021 11:59:11 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 17 Mar 2021 11:59:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kroah.com; h= date:from:to:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=7QQhWXRtOfXvgGHYdeOiNWA7kyE iQ0DNqAkTJJYwQSw=; b=I9/UGegSW5fuuJbuTdU4Nwvb7ZQZKIE3HLcUn5zSenY IYaomRrD2/2HtXqKrRw8DlYyR+ccfQGLu2EldOmsodROm++ksfBcO9x0U6H357E4 Lbifs41pbCTWJRpLWgHQOTN/+eX8JyVDTmy+on93eItox0BxboooFLw1NXSft2lG 87KLsz8KBCjQDDkmHkdk9xtQLW+D6jkclY8jvDZylPvdMSDy/u8NEEZxvNuO9dIX Aay5mfsn5Cqs5P8dZjKKf17LC1shPjWfOHR007vndzg2giNSzUwjczPvjkI/SKKY 9KbyUPj6qx1hkOeQNjG/0BEDyFlHGENISIE+JV9r72g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=7QQhWX RtOfXvgGHYdeOiNWA7kyEiQ0DNqAkTJJYwQSw=; b=t4L+TzWz4LPAccmJc0pvlO ofo+Z3hQamdsor95Jp5x/7aNvjmV0evNYSPK0lrE7qE3Kb+IscQuWRVzGw24LURx pF9wb0nfLNwaZnT8siVH8/Si7mkQrdBqJ5WWKn6hzSwQCOEPgapwHuJ/GzaYIjtY /WgR2kqZR2wE/aeuVPIttAAyz8ZfPCgALbC2WQXrkTd01AHqSvW0A1rI9r3HBlKz rVhgSWmkAZXbzZCnIMGCW20io4vM5NoYoRmSqV+6ldjMgJGN8HwcEtfzt6+rhol8 77n7trEqvjLJ6RgbPXc97YpuncOU0wFPLMqHuV+aLHJ00jwy1i/SEyeCiCkGAOFA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudefgedgkeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesthdtre dttddtvdenucfhrhhomhepifhrvghgucfmjfcuoehgrhgvgheskhhrohgrhhdrtghomheq necuggftrfgrthhtvghrnhepveeuheejgfffgfeivddukedvkedtleelleeghfeljeeiue eggeevueduudekvdetnecukfhppeekfedrkeeirdejgedrieegnecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhrvghgsehkrhhorghhrdgtoh hm X-ME-Proxy: Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) by mail.messagingengine.com (Postfix) with ESMTPA id 866691080064; Wed, 17 Mar 2021 11:59:10 -0400 (EDT) Date: Wed, 17 Mar 2021 16:59:08 +0100 From: Greg KH To: kernelnewbies@kernelnewbies.org Subject: Re: Device file not appearing Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org On Wed, Mar 17, 2021 at 09:52:32AM -0600, Gregory Anders wrote: > Hi all, > > I'm writing a char device driver and am having trouble getting the file to > appear under /dev. > > This isn't my first rodeo: in fact, I've written a few other drivers in the > past and they have all worked as expected. This driver is based on the > source code of those other drivers, so I'm fairly confident I'm doing > everything correctly. So I'm stumped and looking for help. > > Here is what I have in my init function: > > #define DRIVER_NAME "foo" > > static int __init mod_init(void) > { > dev_t devno; > my_class = class_create(THIS_MODULE, DRIVER_NAME); > ret = alloc_chrdev_region(&devno, 0, MAX_DEVICES, DRIVER_NAME); > > my_major = MAJOR(devno); > > ... > } > > (Note that for brevity I'm omitting a lot of boilerplate/error handling, > etc. But you can assume it's all there). > > My driver is also a network driver; in fact, it's *primarily* a network > driver and it provides a char device file that is used to configure the > hardware. I am creating the char device whenever the network device is first > opened (e.g. 'netdev_open' below is the 'ndo_open' field of the 'struct > netdev_ops'): > > struct private_data { > struct cdev cdev; > ... > } > > static int netdev_open(struct net_device *dev) > { > struct private_data *priv = netdev_priv(dev); > dev_t devno; > int minor; > struct device *d; > > minor = ida_alloc_max(&ida, MAX_DEVICES, GFP_KERNEL); > > devno = MKDEV(my_major, minor); > cdev_init(&priv->cdev, &my_fops); > cdev_add(&priv->cdev, devno, 1); > > /* This should create a device node with the same name as the > * network interface, e.g. foo0 > */ > d = device_create(my_class, NULL, devno, priv, dev->name); > if (IS_ERR(d)) { > ... > } > > ... > } > > Again, I'm omitting the error checking for the sake of brevity, but it is > there in the actual code. This function runs successfully and the network > device is successfully opened. The 'device_create' function does not return > an error, but there is nothing beneath /dev as I would expect. > > I'm really stumped here because everything I've been able to find online > says that 'device_create' ought to create that device file. I can see my > class under /sys/class/ and that directory contains a directory with the > name of the device: > > $ ls -1 /sys/class/my_class/ > foo0 > > so it looks like the char device *is* being created, there's just no > corresponding entry under /dev. Is your char device listed in /sys/dev/char/ ? If not, then you have something wrong with your call to device_create(). If so, then you need to look at whatever tool is creating your device nodes in /dev. Usually the kernel handles this with devtmpfs, but I do not know what your system uses for this. Do you have a pointer to the real source code anywhere to be able to see it better to see if you are doing something wrong with the call to device_create()? Also, why a full major? Why not just use the misc_dev api instead that does all of the above "housekeeping" for you automagically? thanks, greg k-h _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies