diff options
Diffstat (limited to 'drivers/edac/edac_mc.c')
-rw-r--r-- | drivers/edac/edac_mc.c | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c index 072aa81b4a70..ff8c0020649c 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c | |||
@@ -101,18 +101,37 @@ const char *edac_mem_types[] = { | |||
101 | }; | 101 | }; |
102 | EXPORT_SYMBOL_GPL(edac_mem_types); | 102 | EXPORT_SYMBOL_GPL(edac_mem_types); |
103 | 103 | ||
104 | /* 'ptr' points to a possibly unaligned item X such that sizeof(X) is 'size'. | 104 | /** |
105 | * Adjust 'ptr' so that its alignment is at least as stringent as what the | 105 | * edac_align_ptr - Prepares the pointer offsets for a single-shot allocation |
106 | * compiler would provide for X and return the aligned result. | 106 | * @p: pointer to a pointer with the memory offset to be used. At |
107 | * return, this will be incremented to point to the next offset | ||
108 | * @size: Size of the data structure to be reserved | ||
109 | * @n_elems: Number of elements that should be reserved | ||
107 | * | 110 | * |
108 | * If 'size' is a constant, the compiler will optimize this whole function | 111 | * If 'size' is a constant, the compiler will optimize this whole function |
109 | * down to either a no-op or the addition of a constant to the value of 'ptr'. | 112 | * down to either a no-op or the addition of a constant to the value of '*p'. |
113 | * | ||
114 | * The 'p' pointer is absolutely needed to keep the proper advancing | ||
115 | * further in memory to the proper offsets when allocating the struct along | ||
116 | * with its embedded structs, as edac_device_alloc_ctl_info() does it | ||
117 | * above, for example. | ||
118 | * | ||
119 | * At return, the pointer 'p' will be incremented to be used on a next call | ||
120 | * to this function. | ||
110 | */ | 121 | */ |
111 | void *edac_align_ptr(void *ptr, unsigned size) | 122 | void *edac_align_ptr(void **p, unsigned size, int n_elems) |
112 | { | 123 | { |
113 | unsigned align, r; | 124 | unsigned align, r; |
125 | void *ptr = *p; | ||
114 | 126 | ||
115 | /* Here we assume that the alignment of a "long long" is the most | 127 | *p += size * n_elems; |
128 | |||
129 | /* | ||
130 | * 'p' can possibly be an unaligned item X such that sizeof(X) is | ||
131 | * 'size'. Adjust 'p' so that its alignment is at least as | ||
132 | * stringent as what the compiler would provide for X and return | ||
133 | * the aligned result. | ||
134 | * Here we assume that the alignment of a "long long" is the most | ||
116 | * stringent alignment that the compiler will ever provide by default. | 135 | * stringent alignment that the compiler will ever provide by default. |
117 | * As far as I know, this is a reasonable assumption. | 136 | * As far as I know, this is a reasonable assumption. |
118 | */ | 137 | */ |
@@ -132,6 +151,8 @@ void *edac_align_ptr(void *ptr, unsigned size) | |||
132 | if (r == 0) | 151 | if (r == 0) |
133 | return (char *)ptr; | 152 | return (char *)ptr; |
134 | 153 | ||
154 | *p += align - r; | ||
155 | |||
135 | return (void *)(((unsigned long)ptr) + align - r); | 156 | return (void *)(((unsigned long)ptr) + align - r); |
136 | } | 157 | } |
137 | 158 | ||
@@ -154,6 +175,7 @@ void *edac_align_ptr(void *ptr, unsigned size) | |||
154 | struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows, | 175 | struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows, |
155 | unsigned nr_chans, int edac_index) | 176 | unsigned nr_chans, int edac_index) |
156 | { | 177 | { |
178 | void *ptr = NULL; | ||
157 | struct mem_ctl_info *mci; | 179 | struct mem_ctl_info *mci; |
158 | struct csrow_info *csi, *csrow; | 180 | struct csrow_info *csi, *csrow; |
159 | struct rank_info *chi, *chp, *chan; | 181 | struct rank_info *chi, *chp, *chan; |
@@ -168,11 +190,11 @@ struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows, | |||
168 | * stringent as what the compiler would provide if we could simply | 190 | * stringent as what the compiler would provide if we could simply |
169 | * hardcode everything into a single struct. | 191 | * hardcode everything into a single struct. |
170 | */ | 192 | */ |
171 | mci = (struct mem_ctl_info *)0; | 193 | mci = edac_align_ptr(&ptr, sizeof(*mci), 1); |
172 | csi = edac_align_ptr(&mci[1], sizeof(*csi)); | 194 | csi = edac_align_ptr(&ptr, sizeof(*csi), nr_csrows); |
173 | chi = edac_align_ptr(&csi[nr_csrows], sizeof(*chi)); | 195 | chi = edac_align_ptr(&ptr, sizeof(*chi), nr_csrows * nr_chans); |
174 | dimm = edac_align_ptr(&chi[nr_chans * nr_csrows], sizeof(*dimm)); | 196 | dimm = edac_align_ptr(&ptr, sizeof(*dimm), nr_csrows * nr_chans); |
175 | pvt = edac_align_ptr(&dimm[nr_chans * nr_csrows], sz_pvt); | 197 | pvt = edac_align_ptr(&ptr, sz_pvt, 1); |
176 | size = ((unsigned long)pvt) + sz_pvt; | 198 | size = ((unsigned long)pvt) + sz_pvt; |
177 | 199 | ||
178 | mci = kzalloc(size, GFP_KERNEL); | 200 | mci = kzalloc(size, GFP_KERNEL); |