In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memset(), avoid intentionally writing across neighboring fields. Add struct_group() to mark region of struct cm4000_dev that should be initialized to zero.
Unified · Split
| @@ -116,8 +116,9 @@ struct cm4000_dev { · 115 unmodified lines | ||
| 116 | 116 | wait_queue_head_t atrq; /* wait for ATR valid */ |
| 117 | 117 | wait_queue_head_t readq; /* used by write to wake blk.read */ |
| 118 | 118 | |
| 119 | − /* warning: do not move this fields. | |
| 119 | + /* warning: do not move this struct group. | |
| 120 | 120 | * initialising to zero depends on it - see ZERO_DEV below. */ |
| 121 | + struct_group(init, | |
| 121 | 122 | unsigned char atr_csum; |
| 122 | 123 | unsigned char atr_len_retry; |
| 123 | 124 | unsigned short atr_len; |
| @@ -140,12 +141,10 @@ struct cm4000_dev { · 16 unmodified lines | ||
| 140 | 141 | |
| 141 | 142 | struct timer_list timer; /* used to keep monitor running */ |
| 142 | 143 | int monitor_running; |
| 144 | + ); | |
| 143 | 145 | }; |
| 144 | 146 | |
| 145 | −#define ZERO_DEV(dev) \ | |
| 146 | − memset(&dev->atr_csum,0, \ | |
| 147 | − sizeof(struct cm4000_dev) - \ | |
| 148 | − offsetof(struct cm4000_dev, atr_csum)) | |
| 147 | +#define ZERO_DEV(dev) memset(&((dev)->init), 0, sizeof((dev)->init)) | |
| 149 | 148 | |
| 150 | 149 | static struct pcmcia_device *dev_table[CM4000_MAX_DEV]; |
| 151 | 150 | static struct class *cmm_class; |