ptp: ocp: Add debugfs entry for timecard
Hello Jonathan Lemon,
The patch f67bf662d2cf: "ptp: ocp: Add debugfs entry for timecard" from Sep 14, 2021, leads to the following Smatch static checker warning:
drivers/ptp/ptp_ocp.c:3102 ptp_ocp_summary_show() warn: right shifting more than type allows 16 vs 16
drivers/ptp/ptp_ocp.c
2969 static int
2970 ptp_ocp_summary_show(struct seq_file *s, void *data)
2971 {
2972 struct device *dev = s->private;
2973 struct ptp_system_timestamp sts;
2974 u16 sma_val[4][2], ctrl, val;
^^^^This "ctrl" variable should probably be a u32.
2975 struct ts_reg __iomem *ts_reg;
2976 struct timespec64 ts;
2977 struct ptp_ocp *bp;
2978 char *src, *buf;
2979 bool on, map;
2980 int i;
2981
2982 buf = (char *)__get_free_page(GFP_KERNEL);
2983 if (!buf)
2984 return -ENOMEM;
2985 [ snip ]
3087
3088 if (bp->fw_cap & OCP_CAP_SIGNAL)
3089 for (i = 0; i < 4; i++)
3090 _signal_summary_show(s, bp, i);
3091
3092 if (bp->fw_cap & OCP_CAP_FREQ)
3093 for (i = 0; i < 4; i++)
3094 _frequency_summary_show(s, i, bp->freq_in[i]);
3095
3096 if (bp->irig_out) {
3097 ctrl = ioread32(&bp->irig_out->ctrl);reads a u32
3098 on = ctrl & IRIG_M_CTRL_ENABLE;
3099 val = ioread32(&bp->irig_out->status);
3100 gpio_output_map(buf, bp, sma_val, 4);
3101 seq_printf(s, "%7s: %s, error: %d, mode %d, out: %s\n", "IRIG",
--> 3102 on ? " ON" : "OFF", val, (ctrl >> 16), buf);
^^^^^^^^^^shifts to zero
3103 }
3104
3105 if (bp->irig_in) {
3106 on = ioread32(&bp->irig_in->ctrl) & IRIG_S_CTRL_ENABLE;
3107 val = ioread32(&bp->irig_in->status);
3108 gpio_input_map(buf, bp, sma_val, 4, NULL);
3109 seq_printf(s, "%7s: %s, error: %d, src: %s\n", "IRIG in",
3110 on ? " ON" : "OFF", val, buf);
3111 }
3112 regards,
dan carpenter
Also:
drivers/ptp/ptp_ocp.c:3154 ptp_ocp_summary_show() warn: right shifting more than type allows 16 vs 16
regards,
dan carpenter
Quoted 68 lines · Dan Carpenter
Hello Jonathan Lemon,
The patch
f67bf662d2cf: "ptp: ocp: Add debugfs entry for timecard" from Sep 14, 2021, leads to the following Smatch static checker warning:drivers/ptp/ptp_ocp.c:3102 ptp_ocp_summary_show() warn: right shifting more than type allows 16 vs 16
drivers/ptp/ptp_ocp.c2969 static int 2970 ptp_ocp_summary_show(struct seq_file *s, void *data) 2971 { 2972 struct device *dev = s->private; 2973 struct ptp_system_timestamp sts; 2974 u16 sma_val[4][2], ctrl, val; ^^^^This "ctrl" variable should probably be a u32.
2975 struct ts_reg __iomem *ts_reg; 2976 struct timespec64 ts; 2977 struct ptp_ocp *bp; 2978 char *src, *buf; 2979 bool on, map; 2980 int i; 2981 2982 buf = (char *)__get_free_page(GFP_KERNEL); 2983 if (!buf) 2984 return -ENOMEM; 2985[ snip ]
3087 3088 if (bp->fw_cap & OCP_CAP_SIGNAL) 3089 for (i = 0; i < 4; i++) 3090 _signal_summary_show(s, bp, i); 3091 3092 if (bp->fw_cap & OCP_CAP_FREQ) 3093 for (i = 0; i < 4; i++) 3094 _frequency_summary_show(s, i, bp->freq_in[i]); 3095 3096 if (bp->irig_out) { 3097 ctrl = ioread32(&bp->irig_out->ctrl);reads a u32
3098 on = ctrl & IRIG_M_CTRL_ENABLE; 3099 val = ioread32(&bp->irig_out->status); 3100 gpio_output_map(buf, bp, sma_val, 4); 3101 seq_printf(s, "%7s: %s, error: %d, mode %d, out: %s\n", "IRIG", --> 3102 on ? " ON" : "OFF", val, (ctrl >> 16), buf); ^^^^^^^^^^shifts to zero
3103 } 3104 3105 if (bp->irig_in) { 3106 on = ioread32(&bp->irig_in->ctrl) & IRIG_S_CTRL_ENABLE; 3107 val = ioread32(&bp->irig_in->status); 3108 gpio_input_map(buf, bp, sma_val, 4, NULL); 3109 seq_printf(s, "%7s: %s, error: %d, src: %s\n", "IRIG in", 3110 on ? " ON" : "OFF", val, buf); 3111 } 3112regards,
dan carpenter