aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlaf Hering <olh@suse.de>2006-02-01 06:05:58 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-02-01 11:53:19 -0500
commite61997881e0402aedbfad8696e369568a0583f14 (patch)
tree2b66d348024b41c22966c386f3ca6647a9efdb00
parent39931e41becd6abeb2014747369d8b6392f5dbac (diff)
[PATCH] MODALIAS= for macio
Prodive a MODALIAS= enviroment variable for devices on the mac-io bus. Change the buffer length counter to not waste memory by advancing the pointer for the next string too far. Tested on an ibook1 with modular pmac_zilog. Signed-off-by: Olaf Hering <olh@suse.de> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/macintosh/macio_asic.c72
1 files changed, 48 insertions, 24 deletions
diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
index ed6d3174d660..69596f6438e9 100644
--- a/drivers/macintosh/macio_asic.c
+++ b/drivers/macintosh/macio_asic.c
@@ -140,10 +140,9 @@ static int macio_uevent(struct device *dev, char **envp, int num_envp,
140{ 140{
141 struct macio_dev * macio_dev; 141 struct macio_dev * macio_dev;
142 struct of_device * of; 142 struct of_device * of;
143 char *scratch, *compat; 143 char *scratch, *compat, *compat2;
144 int i = 0; 144 int i = 0;
145 int length = 0; 145 int length, cplen, cplen2, seen = 0;
146 int cplen, seen = 0;
147 146
148 if (!dev) 147 if (!dev)
149 return -ENODEV; 148 return -ENODEV;
@@ -153,23 +152,22 @@ static int macio_uevent(struct device *dev, char **envp, int num_envp,
153 return -ENODEV; 152 return -ENODEV;
154 153
155 of = &macio_dev->ofdev; 154 of = &macio_dev->ofdev;
156 scratch = buffer;
157 155
158 /* stuff we want to pass to /sbin/hotplug */ 156 /* stuff we want to pass to /sbin/hotplug */
159 envp[i++] = scratch; 157 envp[i++] = scratch = buffer;
160 length += scnprintf (scratch, buffer_size - length, "OF_NAME=%s", 158 length = scnprintf (scratch, buffer_size, "OF_NAME=%s", of->node->name);
161 of->node->name);
162 if ((buffer_size - length <= 0) || (i >= num_envp))
163 return -ENOMEM;
164 ++length; 159 ++length;
160 buffer_size -= length;
161 if ((buffer_size <= 0) || (i >= num_envp))
162 return -ENOMEM;
165 scratch += length; 163 scratch += length;
166 164
167 envp[i++] = scratch; 165 envp[i++] = scratch;
168 length += scnprintf (scratch, buffer_size - length, "OF_TYPE=%s", 166 length = scnprintf (scratch, buffer_size, "OF_TYPE=%s", of->node->type);
169 of->node->type);
170 if ((buffer_size - length <= 0) || (i >= num_envp))
171 return -ENOMEM;
172 ++length; 167 ++length;
168 buffer_size -= length;
169 if ((buffer_size <= 0) || (i >= num_envp))
170 return -ENOMEM;
173 scratch += length; 171 scratch += length;
174 172
175 /* Since the compatible field can contain pretty much anything 173 /* Since the compatible field can contain pretty much anything
@@ -177,29 +175,55 @@ static int macio_uevent(struct device *dev, char **envp, int num_envp,
177 * up using a number of environment variables instead. */ 175 * up using a number of environment variables instead. */
178 176
179 compat = (char *) get_property(of->node, "compatible", &cplen); 177 compat = (char *) get_property(of->node, "compatible", &cplen);
178 compat2 = compat;
179 cplen2= cplen;
180 while (compat && cplen > 0) { 180 while (compat && cplen > 0) {
181 int l;
182 envp[i++] = scratch; 181 envp[i++] = scratch;
183 length += scnprintf (scratch, buffer_size - length, 182 length = scnprintf (scratch, buffer_size,
184 "OF_COMPATIBLE_%d=%s", seen, compat); 183 "OF_COMPATIBLE_%d=%s", seen, compat);
185 if ((buffer_size - length <= 0) || (i >= num_envp)) 184 ++length;
185 buffer_size -= length;
186 if ((buffer_size <= 0) || (i >= num_envp))
186 return -ENOMEM; 187 return -ENOMEM;
187 length++;
188 scratch += length; 188 scratch += length;
189 l = strlen (compat) + 1; 189 length = strlen (compat) + 1;
190 compat += l; 190 compat += length;
191 cplen -= l; 191 cplen -= length;
192 seen++; 192 seen++;
193 } 193 }
194 194
195 envp[i++] = scratch; 195 envp[i++] = scratch;
196 length += scnprintf (scratch, buffer_size - length, 196 length = scnprintf (scratch, buffer_size, "OF_COMPATIBLE_N=%d", seen);
197 "OF_COMPATIBLE_N=%d", seen);
198 if ((buffer_size - length <= 0) || (i >= num_envp))
199 return -ENOMEM;
200 ++length; 197 ++length;
198 buffer_size -= length;
199 if ((buffer_size <= 0) || (i >= num_envp))
200 return -ENOMEM;
201 scratch += length;
202
203 envp[i++] = scratch;
204 length = scnprintf (scratch, buffer_size, "MODALIAS=of:N%sT%s",
205 of->node->name, of->node->type);
206 /* overwrite '\0' */
207 buffer_size -= length;
208 if ((buffer_size <= 0) || (i >= num_envp))
209 return -ENOMEM;
201 scratch += length; 210 scratch += length;
202 211
212 if (!compat2) {
213 compat2 = "";
214 cplen2 = 1;
215 }
216 while (cplen2 > 0) {
217 length = snprintf (scratch, buffer_size, "C%s", compat2);
218 buffer_size -= length;
219 if (buffer_size <= 0)
220 return -ENOMEM;
221 scratch += length;
222 length = strlen (compat2) + 1;
223 compat2 += length;
224 cplen2 -= length;
225 }
226
203 envp[i] = NULL; 227 envp[i] = NULL;
204 228
205 return 0; 229 return 0;