From: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
To: Michal Simek <michal.simek@xilinx.com>
Cc: linux-kernel@vger.kernel.org, monstr@monstr.eu,
Alan Tull <atull@altera.com>, Pavel Machek <pavel@ucw.cz>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Dinh Nguyen <dinguyen@altera.com>,
Philip Balister <philip@balister.org>,
Alessandro Rubini <rubini@gnudd.com>,
Steffen Trumtrar <s.trumtrar@pengutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>,
Jason Cooper <jason@lakedaemon.net>,
Yves Vandervennet <rocket.yvanderv@gmail.com>,
Kyle Teske <kyle.teske@ni.com>,
Josh Cartwright <joshc@eso.teric.us>,
Rob Landley <rob@landley.net>,
Mauro Carvalho Chehab <m.chehab@samsung.com>,
Andrew Morton <akpm@linux-foundation.org>,
Cesar Eduardo Barros <cesarb@cesarb.net>,
Joe Perches <joe@perches.com>,
"David S. Miller" <davem@davemloft.net>,
David Brown <davidb@codeaurora.org>,
Samuel Ortiz <sameo@linux.intel.com>,
Nicolas Pitre <nico@linaro.org>,
Mark Langsdorf <mark.langsdorf@calxeda.com>,
Felipe Balbi <balbi@ti.com>,
linux-doc@vger.kernel.org
Subject: Re: [RFC PATCH v2] fpga: Introduce new fpga subsystem
Date: Wed, 2 Oct 2013 11:46:40 -0600 [thread overview]
Message-ID: <20131002174640.GA10287@obsidianresearch.com> (raw)
In-Reply-To: <fe4f34387011339efe9f5868a7eec9d549462d8f.1380727889.git.michal.simek@xilinx.com>
On Wed, Oct 02, 2013 at 05:35:58PM +0200, Michal Simek wrote:
> +What: /sys/class/fpga_manager/fpga<dev-id>/fpga_config_state
> +Date: October 2013
> +KernelVersion: 3.12
> +Contact: Michal Simek <michal.simek@xilinx.com>
> +Description:
> + By reading this file you will get current fpga manager state.
> + Flag bits are present in include/linux/fpga.h (FPGA_MGR_XX).
> + By writing to this file you can change fpga manager state.
> + Valid options are: write_init, write_complete, read_init,
> + read_complete.
This shouldn't be asymmetric - read/write should be in the same
format.
I strongly encourage you to use text strings to indicate the state of
the configuration FSM, and I *really* think you should rework things
to have an explicit configuration FSM rather than trying to bodge one
together with a bunch of bit flags.
Plus error handling is missing, failures need to be reported back.
Noticed several typos:
> +
> + if (mgr->mops->read_init) {
> + ret = mgr->mops->read_init(mgr);
> + if (ret) {
> + dev_dbg(mgr->dev, "Failed to write_init\n");
^^^^^^^^
read_init
> + if (mgr->mops->write) {
^^^^^^^^^^
read
> + ret = mgr->mops->read(mgr, buf, count);
> + if (ret) {
> + dev_dbg(mgr->dev, "Failed to write\n");
^^^^^^^^^^^^^^^^^
read
> +
> + if (mgr->mops->write_complete) {
^^^^^^^^^^
read
> + ret = mgr->mops->read_complete(mgr);
> + if (ret) {
> + dev_dbg(mgr->dev, "Failed to write_complete\n");
^^^^^^^^^^^^
read
> +static inline int fpga_mgr_write(struct fpga_manager *mgr, const u8 *buf,
> + ssize_t count)
> +{
> + int bit, ret;
> +
> + dev_dbg(mgr->dev, "%s %lx\n", __func__, mgr->flags);
> +
> + /* FPGE init has to be done to be able to continue */
^^^^^^
FPGA
> +static struct device_attribute fpga_mgr_attrs[] = {
> + __ATTR(name, S_IRUGO, fpga_mgr_name_show, NULL),
> + __ATTR(firmware, S_IWUSR, NULL, fpga_mgr_attr_write),
> + __ATTR(fpga_config_state, S_IRUSR | S_IWUSR,
> + fpga_mgr_status_read, fpga_mgr_status_write),
> + __ATTR_NULL
> +};
AFAIK it is preferred to use DEVICE_ATTR_RO(), ATTRIBUTE_GROUPS()
and struct class.dev_groups
eg see this note in linux/device.h
struct class {
struct device_attribute *dev_attrs; /* use dev_groups instead */
const struct attribute_group **dev_groups;
}
> + struct fpga_manager *mgr;
> + int ret;
> +
> + if (!mops) {
> + dev_dbg(&pdev->dev, "Register failed: NO fpga_manager_ops\n");
> + return -EINVAL;
> + }
> +
> + if (!name || !strlen(name)) {
> + dev_dbg(&pdev->dev, "Register failed: NO name specific\n");
> + return -EINVAL;
> + }
> +
> + mgr = devm_kzalloc(&pdev->dev, sizeof(*mgr), GFP_KERNEL);
> + if (!mgr)
> + return -ENOMEM;
I wonder if this is right, it seems like a strange way to make a class
subsystem, usually the struct fpga_manager would contain the 'struct
device' (not a pointer, so you can use container_of) and drvdata would
be reserved for something else.
This seems to create lifetime issues since the devm above will be
free'd when the platform driver is released, but the class device will
live on with the stray pointer. Better to allocate everything against
the class device below.
Plus you need to ensure the device is fully functionally before
device_register is called, otherwise you race with notifications to
userspace.
> +/**
> + * fpga_mgr_unregister: Remove fpga manager
> + * @pdev: Pointer to the platform device of fpga manager
> + *
> + * Function unregister fpga manager and release all temporary structures
> + *
> + * Returns 0 for all cases
> + */
> +int fpga_mgr_unregister(struct platform_device *pdev)
> +{
> + struct fpga_manager *mgr = platform_get_drvdata(pdev);
> +
> + if (mgr && mgr->mops && mgr->mops->fpga_remove)
> + mgr->mops->fpga_remove(mgr);
> +
> + device_unregister(mgr->dev);
> +
> + spin_lock(&fpga_mgr_idr_lock);
> + idr_remove(&fpga_mgr_idr, mgr->nr);
> + spin_unlock(&fpga_mgr_idr_lock);
What happens when userspace is holding one of the sysfs files open and
you unload the module? Looks like bad things?
Regards,
Jason
next prev parent reply other threads:[~2013-10-02 17:52 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-02 15:35 [RFC PATCH v2 0/1] FPGA subsystem core Michal Simek
2013-10-02 15:35 ` [RFC PATCH v2] fpga: Introduce new fpga subsystem Michal Simek
2013-10-02 16:06 ` Joe Perches
2013-10-04 16:15 ` Michal Simek
2013-10-04 16:26 ` Greg Kroah-Hartman
2013-10-02 17:46 ` Jason Gunthorpe [this message]
2013-10-04 16:28 ` Michal Simek
2013-10-04 17:05 ` Jason Gunthorpe
2013-10-04 18:50 ` Alan Tull
2013-10-02 19:00 ` [RFC PATCH v2 0/1] FPGA subsystem core H. Peter Anvin
2013-10-03 6:49 ` Pavel Machek
2013-10-04 13:57 ` Michal Simek
2013-10-04 14:16 ` Greg Kroah-Hartman
2013-10-04 14:21 ` H. Peter Anvin
2013-10-04 14:28 ` Michal Simek
2013-10-04 16:46 ` H. Peter Anvin
2013-10-04 17:44 ` Michal Simek
2013-10-04 18:12 ` H. Peter Anvin
2013-10-04 23:33 ` Greg Kroah-Hartman
2013-10-04 23:49 ` Jason Gunthorpe
2013-10-05 4:00 ` H. Peter Anvin
2013-10-05 5:10 ` Jason Gunthorpe
2013-10-05 5:34 ` H. Peter Anvin
2013-10-05 6:53 ` Michal Simek
[not found] ` <c59c68b8-2565-45c5-bfe9-574b76f3f9bc@email.android.com>
2013-10-07 13:11 ` Michal Simek
2013-10-07 14:55 ` H. Peter Anvin
2013-10-07 15:03 ` Michal Simek
2013-10-07 15:07 ` H. Peter Anvin
2013-10-08 13:00 ` Michal Simek
2013-10-08 16:49 ` Alan Tull
2013-10-08 21:42 ` Greg Kroah-Hartman
[not found] ` <CANk1AXS9fpypVVWgvvUCZjKXDvLPpB7=kCNucwFcktgBHmV37w@mail.gmail.com>
[not found] ` <20131009014027.GA17066@kroah.com>
[not found] ` <5254EC8A.8060609@monstr.eu>
[not found] ` <20131009055332.GA4510@kroah.com>
[not found] ` <52550638.2080301@monstr.eu>
[not found] ` <52556585.3050603@zytor.com>
[not found] ` <20131009192439.GC18611@kroah.com>
[not found] ` <5255BE71.8010801@zytor.com>
2013-10-09 21:07 ` Jason Gunthorpe
2013-10-09 22:21 ` H. Peter Anvin
2013-10-05 17:33 ` Jason Gunthorpe
2013-10-05 6:56 ` Michal Simek
2013-10-04 23:50 ` H. Peter Anvin
2013-10-05 6:49 ` Michal Simek
2013-10-08 17:00 ` Alan Tull
2013-10-08 21:44 ` Greg Kroah-Hartman
2013-10-08 23:47 ` delicious quinoa
2013-10-09 1:41 ` Greg Kroah-Hartman
2013-10-04 18:26 ` Alan Tull
2013-10-03 21:46 ` Alan Tull
2013-10-04 15:27 ` Michal Simek
2013-10-04 18:30 ` Alan Tull
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131002174640.GA10287@obsidianresearch.com \
--to=jgunthorpe@obsidianresearch.com \
--cc=akpm@linux-foundation.org \
--cc=atull@altera.com \
--cc=balbi@ti.com \
--cc=cesarb@cesarb.net \
--cc=davem@davemloft.net \
--cc=davidb@codeaurora.org \
--cc=dinguyen@altera.com \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=jason@lakedaemon.net \
--cc=joe@perches.com \
--cc=joshc@eso.teric.us \
--cc=kyle.teske@ni.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.chehab@samsung.com \
--cc=mark.langsdorf@calxeda.com \
--cc=michal.simek@xilinx.com \
--cc=monstr@monstr.eu \
--cc=nico@linaro.org \
--cc=pavel@ucw.cz \
--cc=philip@balister.org \
--cc=rob@landley.net \
--cc=rocket.yvanderv@gmail.com \
--cc=rubini@gnudd.com \
--cc=s.trumtrar@pengutronix.de \
--cc=sameo@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).