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=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 6FA43C4332B for ; Tue, 24 Mar 2020 12:31:59 +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 0C1A52070A for ; Tue, 24 Mar 2020 12:31:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kroah.com header.i=@kroah.com header.b="kcEs8b5j"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WKUwWLDa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C1A52070A 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.92.3) (envelope-from ) id 1jGii9-0002zr-6C; Tue, 24 Mar 2020 08:31:13 -0400 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by shelob.surriel.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1jGii4-0002zj-A5 for kernelnewbies@kernelnewbies.org; Tue, 24 Mar 2020 08:31:08 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 5A2565C01FC; Tue, 24 Mar 2020 08:31:05 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 24 Mar 2020 08:31:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kroah.com; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=j+cSSRPPPGhUnBIDbqVakEpoA5U +7q3A3aF+luExXwo=; b=kcEs8b5jnxJWFfOT2JPRqrYegUXXDOgxuE1pWxwn/RK AEJdv7ds2YH3BgUc8t9pFelaH2dMEicI5r4yGBjETv6mjCDU5U1MemFaANUk7/PP PEGd8tgpghZwUG8NjDIYNsR3hfAjWBCTO8qryxrA1Hb9dHjzn9iy5oWpnl7AAUXx YytefLKtC/qygmLjXimRx0pX19nM7hVoMf6QA1R8OIw29/+F08Ruc/5Wg/31TcGd n8ypvDe6yXMgkm5WTnjTJ+VZ9x6VFoeJb1brVp7mCXeC/CGYP61/4hTd45KaRuci MfPFghsrBXqJzAJtFLx3Crlu2jHHNXO7vuWJG+9I7Yw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=j+cSSR PPPGhUnBIDbqVakEpoA5U+7q3A3aF+luExXwo=; b=WKUwWLDa/3tsL6livI/WqO M4VydHUaRfZ2ED5a4Ws2xc3w6rDIiC9tSPWAPOgtElQdwmh6Jf1rpykIx/7Gs/Gm uLf14IBq2gagj6541NnH1NNESAjC6V9GJ0AD8bAWA9/smkxBDTV5hDOHapSN6ubY NbUMKI3xgthE1+9D7vDEzrZTYyJ0yPVaaRfc5pN73g5SQlNVbAwwDou8t3s1rhGQ Vpm/zA3JCVfuPHuRCGLMwXNwZgz5+KBNdeekPeBWvIxfbdLgJ8IYRc3RZYojLAAo yiciS6dMWdETFUwjpdzW6fZ0EHwTskzK62/ZZMrq5ROL4ofAL0WtL3fPJS2QfBfw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudehuddguddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefirhgvghcu mffjuceoghhrvghgsehkrhhorghhrdgtohhmqeenucfkphepkeefrdekiedrkeelrddutd ejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhr vghgsehkrhhorghhrdgtohhm X-ME-Proxy: Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) by mail.messagingengine.com (Postfix) with ESMTPA id 6A6FF306472D; Tue, 24 Mar 2020 08:31:04 -0400 (EDT) Date: Tue, 24 Mar 2020 13:31:02 +0100 From: Greg KH To: Pelle Windestam Subject: Re: Accessing rpmsg_device in sysfs attribute functions Message-ID: <20200324123102.GB2348009@kroah.com> References: <117a9e9d420f444ea814a37596fe5693@tagmaster.com> <20200324063113.GA1978604@kroah.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Cc: "kernelnewbies@kernelnewbies.org" 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 Tue, Mar 24, 2020 at 12:02:15PM +0000, Pelle Windestam wrote: > > On Tue, Mar 24, 2020 at 05:34:44AM +0000, Pelle Windestam wrote: > > > Hi, > > > > > > I am trying to develop a simple driver for the rpmsg bus, in order to send > > various commands from user space in Linux to a secondary CPU (A Cortex M4). > > I'm trying to keep things as simple as possible, so my idea was to create a > > driver that just has a few attributes which can be set in /sys which would > > trigger commands to be sent to the M4 CPU. I have the communication between > > the CPU:s up and running, but where I'm having trouble moving forward is how > > to access the "struct rpmsg_device *" that I need in order to communicate > > with the endpoint for the M4 CPU from the store/show function of the sysfs > > attributes. What my driver does is to register a rpmsg_driver in the init > > function: > > > > > > register_rpmsg_driver(&pwm_rpmsg_driver); > > > > > > the device_driver member of my rpmsg_driver struct has its groups member > > set to my driver attribute groups array: > > > static struct rpmsg_driver pwm_rpmsg_driver = { > > > .probe = pwm_rpmsg_probe, > > > .remove = pwm_rpmsg_remove, > > > .callback = pwm_rpmsg_cb, > > > .id_table = pwm_rpmsg_device_id_table, > > > .drv = { > > > .groups = driver_pwm_groups, > > > .name = "pwm_rpmsg", > > > }, > > > }; > > > > > > My issue is that that I am not sure how to access the struct "rpmsg_device > > *" (i.e. from the probe() function) in the show/store functions for the sysfs > > attributes, which have a "struct device_driver *" argument: > > > > That is because you have created a driver attribute, not a device attribute. > > Create device attributes and you should be fine, they bind to the device your > > driver is passed. > > Thanks! Changing them to device attributes was a breeze. Now I am > slightly confused about the "struct device *" argument to the > store/show functions. I was under the impression that this would be > the "struct device" in the struct rpmsg_device, (which would let me > get the struct rpmsg_device using container_of()?), but it appears to > be some completely other device (by looking at the pointer address). I > have tried searching the kernel code for similar example, but I have > not found anything so far. It feels like I am stumbling a bit in the > dark here, looking for my rpmsg_device. It's a bit hard to figure out what exactly you are doing here without a pointer to the code itself :) Are you sure you aren't pointing the platform device accidentally? thanks, greg k-h _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies