soc/qman: add return value to interrupt coalesce changing APIs
authorMadalin Bucur <madalin.bucur@nxp.com>
Wed, 21 Nov 2018 11:41:08 +0000 (13:41 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 23 Nov 2018 19:17:06 +0000 (11:17 -0800)
Check that the values received by the portal interrupt coalesce
change APIs are in range.

Signed-off-by: Madalin Bucur <madalin.bucur@nxp.com>
Signed-off-by: Roy Pledge <roy.pledge@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/soc/fsl/qbman/qman.c
include/soc/fsl/qman.h

index ce7c03052e3365be0e9ca72684f9d4b21cee2231..52c153cd795a8c471b48eb570fa87e5613244c2e 100644 (file)
@@ -36,6 +36,8 @@
 #define MAX_IRQNAME    16      /* big enough for "QMan portal %d" */
 #define QMAN_POLL_LIMIT 32
 #define QMAN_PIRQ_DQRR_ITHRESH 12
+#define QMAN_DQRR_IT_MAX 15
+#define QMAN_ITP_MAX 0xFFF
 #define QMAN_PIRQ_MR_ITHRESH 4
 #define QMAN_PIRQ_IPERIOD 100
 
@@ -727,9 +729,15 @@ static inline void qm_dqrr_vdqcr_set(struct qm_portal *portal, u32 vdqcr)
        qm_out(portal, QM_REG_DQRR_VDQCR, vdqcr);
 }
 
-static inline void qm_dqrr_set_ithresh(struct qm_portal *portal, u8 ithresh)
+static inline int qm_dqrr_set_ithresh(struct qm_portal *portal, u8 ithresh)
 {
+
+       if (ithresh > QMAN_DQRR_IT_MAX)
+               return -EINVAL;
+
        qm_out(portal, QM_REG_DQRR_ITR, ithresh);
+
+       return 0;
 }
 
 /* --- MR API --- */
@@ -1012,13 +1020,20 @@ static inline void put_affine_portal(void)
 
 static struct workqueue_struct *qm_portal_wq;
 
-void qman_dqrr_set_ithresh(struct qman_portal *portal, u8 ithresh)
+int qman_dqrr_set_ithresh(struct qman_portal *portal, u8 ithresh)
 {
+       int res;
+
        if (!portal)
-               return;
+               return -EINVAL;
+
+       res = qm_dqrr_set_ithresh(&portal->p, ithresh);
+       if (res)
+               return res;
 
-       qm_dqrr_set_ithresh(&portal->p, ithresh);
        portal->p.dqrr.ithresh = ithresh;
+
+       return 0;
 }
 EXPORT_SYMBOL(qman_dqrr_set_ithresh);
 
@@ -1036,10 +1051,14 @@ void qman_portal_get_iperiod(struct qman_portal *portal, u32 *iperiod)
 }
 EXPORT_SYMBOL(qman_portal_get_iperiod);
 
-void qman_portal_set_iperiod(struct qman_portal *portal, u32 iperiod)
+int qman_portal_set_iperiod(struct qman_portal *portal, u32 iperiod)
 {
-       if (portal)
-               qm_out(&portal->p, QM_REG_ITPR, iperiod);
+       if (!portal || iperiod > QMAN_ITP_MAX)
+               return -EINVAL;
+
+       qm_out(&portal->p, QM_REG_ITPR, iperiod);
+
+       return 0;
 }
 EXPORT_SYMBOL(qman_portal_set_iperiod);
 
index 56877660d5ba34df26dd9cd177fb729868a718b8..5cc7af06c1baa9eced1d276ebfef272909cc1520 100644 (file)
@@ -1205,8 +1205,10 @@ void qman_dqrr_get_ithresh(struct qman_portal *portal, u8 *ithresh);
  * qman_dqrr_set_ithresh - Set coalesce interrupt threshold
  * @portal: portal to set the new value on
  * @ithresh: new threshold value
+ *
+ * Returns 0 on success, or a negative error code.
  */
-void qman_dqrr_set_ithresh(struct qman_portal *portal, u8 ithresh);
+int qman_dqrr_set_ithresh(struct qman_portal *portal, u8 ithresh);
 
 /**
  * qman_dqrr_get_iperiod - Get coalesce interrupt period
@@ -1219,7 +1221,9 @@ void qman_portal_get_iperiod(struct qman_portal *portal, u32 *iperiod);
  * qman_dqrr_set_iperiod - Set coalesce interrupt period
  * @portal: portal to set the new value on
  * @ithresh: new period value
+ *
+ * Returns 0 on success, or a negative error code.
  */
-void qman_portal_set_iperiod(struct qman_portal *portal, u32 iperiod);
+int qman_portal_set_iperiod(struct qman_portal *portal, u32 iperiod);
 
 #endif /* __FSL_QMAN_H */