staging/rdma/hfi1: Use device file minor to identify EPROM
authorDean Luick <dean.luick@intel.com>
Wed, 3 Feb 2016 22:34:58 +0000 (14:34 -0800)
committerDoug Ledford <dledford@redhat.com>
Fri, 11 Mar 2016 01:37:54 +0000 (20:37 -0500)
When writing to the EPROM, the driver will always use the
"first" device.  This is incorrect for multiple cards.

Use the device file minor to determine the device to use.
Reject the generic device file.

Reviewed-by: Mitko Haralanov <mitko.haralanov@intel.com>
Signed-off-by: Dean Luick <dean.luick@intel.com>
Signed-off-by: Jubin John <jubin.john@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/staging/rdma/hfi1/eprom.c
drivers/staging/rdma/hfi1/eprom.h
drivers/staging/rdma/hfi1/file_ops.c

index fb620c97f592dffe4a72c0b1bb6044bbacc2b890..8104a1121bf2ae4b9f32b7276b0935ba4829c616 100644 (file)
@@ -353,21 +353,26 @@ static inline u32 extract_rstart(u32 composite)
  *
  * Return 0 on success, -ERRNO on error
  */
-int handle_eprom_command(const struct hfi1_cmd *cmd)
+int handle_eprom_command(struct file *fp, const struct hfi1_cmd *cmd)
 {
        struct hfi1_devdata *dd;
        u32 dev_id;
        u32 rlen;       /* range length */
        u32 rstart;     /* range start */
+       int i_minor;
        int ret = 0;
 
        /*
-        * The EPROM is per-device, so use unit 0 as that will always
-        * exist.
+        * Map the device file to device data using the relative minor.
+        * The device file minor number is the unit number + 1.  0 is
+        * the generic device file - reject it.
         */
-       dd = hfi1_lookup(0);
+       i_minor = iminor(file_inode(fp)) - HFI1_USER_MINOR_BASE;
+       if (i_minor <= 0)
+               return -EINVAL;
+       dd = hfi1_lookup(i_minor - 1);
        if (!dd) {
-               pr_err("%s: cannot find unit 0!\n", __func__);
+               pr_err("%s: cannot find unit %d!\n", __func__, i_minor);
                return -EINVAL;
        }
 
index 64a64276be8193b59f36fc73ce40dee491ace234..5a61ba3ba8102ee182c1a0b0fdcb940b43a58cd1 100644 (file)
@@ -52,4 +52,4 @@ struct hfi1_cmd;
 struct hfi1_devdata;
 
 int eprom_init(struct hfi1_devdata *dd);
-int handle_eprom_command(const struct hfi1_cmd *cmd);
+int handle_eprom_command(struct file *fp, const struct hfi1_cmd *cmd);
index 2de9032857d33725d92973431f65a78a49c41384..cc681f7bc5705a80d0d3808a1c163484d843d75b 100644 (file)
@@ -409,7 +409,7 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data,
        case HFI1_CMD_EP_ERASE_RANGE:
        case HFI1_CMD_EP_READ_RANGE:
        case HFI1_CMD_EP_WRITE_RANGE:
-               ret = handle_eprom_command(&cmd);
+               ret = handle_eprom_command(fp, &cmd);
                break;
        }
 
This page took 0.02801 seconds and 5 git commands to generate.