mmc: use sysfs groups to handle conditional attributes

Suppressing uevents turned out to be a bad idea as it screws up the
order of events, making user space very confused. Change the system to
use sysfs groups instead.

This is a regression that, for some odd reason, has gone unnoticed for
some time. It confuses hal so that the block devices (which have the
mmc device as a parent) are not registered. End result being that
desktop magic when cards are inserted won't work.

Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Pierre Ossman and committed by Linus Torvalds 51ec92e2 03c086a7

+96 -198
+1 -1
drivers/mmc/core/Makefile
··· 7 7 endif 8 8 9 9 obj-$(CONFIG_MMC) += mmc_core.o 10 - mmc_core-y := core.o sysfs.o bus.o host.o \ 10 + mmc_core-y := core.o bus.o host.o \ 11 11 mmc.o mmc_ops.o sd.o sd_ops.o \ 12 12 sdio.o sdio_ops.o sdio_bus.o \ 13 13 sdio_cis.o sdio_io.o sdio_irq.o
+3 -20
drivers/mmc/core/bus.c
··· 17 17 #include <linux/mmc/card.h> 18 18 #include <linux/mmc/host.h> 19 19 20 - #include "sysfs.h" 21 20 #include "core.h" 22 21 #include "sdio_cis.h" 23 22 #include "bus.h" ··· 42 43 } 43 44 44 45 static struct device_attribute mmc_dev_attrs[] = { 45 - MMC_ATTR_RO(type), 46 + __ATTR(type, S_IRUGO, mmc_type_show, NULL), 46 47 __ATTR_NULL, 47 48 }; 48 49 ··· 188 189 /* 189 190 * Allocate and initialise a new MMC card structure. 190 191 */ 191 - struct mmc_card *mmc_alloc_card(struct mmc_host *host) 192 + struct mmc_card *mmc_alloc_card(struct mmc_host *host, struct device_type *type) 192 193 { 193 194 struct mmc_card *card; 194 195 ··· 203 204 card->dev.parent = mmc_classdev(host); 204 205 card->dev.bus = &mmc_bus_type; 205 206 card->dev.release = mmc_release_card; 207 + card->dev.type = type; 206 208 207 209 return card; 208 210 } ··· 248 248 type, card->rca); 249 249 } 250 250 251 - card->dev.uevent_suppress = 1; 252 - 253 251 ret = device_add(&card->dev); 254 252 if (ret) 255 253 return ret; 256 - 257 - if (card->host->bus_ops->sysfs_add) { 258 - ret = card->host->bus_ops->sysfs_add(card->host, card); 259 - if (ret) { 260 - device_del(&card->dev); 261 - return ret; 262 - } 263 - } 264 - 265 - card->dev.uevent_suppress = 0; 266 - 267 - kobject_uevent(&card->dev.kobj, KOBJ_ADD); 268 254 269 255 mmc_card_set_present(card); 270 256 ··· 271 285 printk(KERN_INFO "%s: card %04x removed\n", 272 286 mmc_hostname(card->host), card->rca); 273 287 } 274 - 275 - if (card->host->bus_ops->sysfs_remove) 276 - card->host->bus_ops->sysfs_remove(card->host, card); 277 288 device_del(&card->dev); 278 289 } 279 290
+10 -1
drivers/mmc/core/bus.h
··· 11 11 #ifndef _MMC_CORE_BUS_H 12 12 #define _MMC_CORE_BUS_H 13 13 14 - struct mmc_card *mmc_alloc_card(struct mmc_host *host); 14 + #define MMC_DEV_ATTR(name, fmt, args...) \ 15 + static ssize_t mmc_##name##_show (struct device *dev, struct device_attribute *attr, char *buf) \ 16 + { \ 17 + struct mmc_card *card = container_of(dev, struct mmc_card, dev); \ 18 + return sprintf(buf, fmt, args); \ 19 + } \ 20 + static DEVICE_ATTR(name, S_IRUGO, mmc_##name##_show, NULL) 21 + 22 + struct mmc_card *mmc_alloc_card(struct mmc_host *host, 23 + struct device_type *type); 15 24 int mmc_add_card(struct mmc_card *card); 16 25 void mmc_remove_card(struct mmc_card *card); 17 26
-2
drivers/mmc/core/core.h
··· 18 18 struct mmc_bus_ops { 19 19 void (*remove)(struct mmc_host *); 20 20 void (*detect)(struct mmc_host *); 21 - int (*sysfs_add)(struct mmc_host *, struct mmc_card *card); 22 - void (*sysfs_remove)(struct mmc_host *, struct mmc_card *card); 23 21 void (*suspend)(struct mmc_host *); 24 22 void (*resume)(struct mmc_host *); 25 23 };
+39 -51
drivers/mmc/core/mmc.c
··· 17 17 #include <linux/mmc/mmc.h> 18 18 19 19 #include "core.h" 20 - #include "sysfs.h" 21 20 #include "bus.h" 22 21 #include "mmc_ops.h" 23 22 ··· 247 248 return err; 248 249 } 249 250 251 + MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1], 252 + card->raw_cid[2], card->raw_cid[3]); 253 + MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], 254 + card->raw_csd[2], card->raw_csd[3]); 255 + MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); 256 + MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); 257 + MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); 258 + MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); 259 + MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name); 260 + MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid); 261 + MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial); 262 + 263 + static struct attribute *mmc_std_attrs[] = { 264 + &dev_attr_cid.attr, 265 + &dev_attr_csd.attr, 266 + &dev_attr_date.attr, 267 + &dev_attr_fwrev.attr, 268 + &dev_attr_hwrev.attr, 269 + &dev_attr_manfid.attr, 270 + &dev_attr_name.attr, 271 + &dev_attr_oemid.attr, 272 + &dev_attr_serial.attr, 273 + NULL, 274 + }; 275 + 276 + static struct attribute_group mmc_std_attr_group = { 277 + .attrs = mmc_std_attrs, 278 + }; 279 + 280 + static struct attribute_group *mmc_attr_groups[] = { 281 + &mmc_std_attr_group, 282 + NULL, 283 + }; 284 + 285 + static struct device_type mmc_type = { 286 + .groups = mmc_attr_groups, 287 + }; 288 + 250 289 /* 251 290 * Handle the detection and initialisation of a card. 252 291 * ··· 345 308 /* 346 309 * Allocate card structure. 347 310 */ 348 - card = mmc_alloc_card(host); 311 + card = mmc_alloc_card(host, &mmc_type); 349 312 if (IS_ERR(card)) { 350 313 err = PTR_ERR(card); 351 314 goto err; ··· 496 459 } 497 460 } 498 461 499 - MMC_ATTR_FN(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1], 500 - card->raw_cid[2], card->raw_cid[3]); 501 - MMC_ATTR_FN(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], 502 - card->raw_csd[2], card->raw_csd[3]); 503 - MMC_ATTR_FN(date, "%02d/%04d\n", card->cid.month, card->cid.year); 504 - MMC_ATTR_FN(fwrev, "0x%x\n", card->cid.fwrev); 505 - MMC_ATTR_FN(hwrev, "0x%x\n", card->cid.hwrev); 506 - MMC_ATTR_FN(manfid, "0x%06x\n", card->cid.manfid); 507 - MMC_ATTR_FN(name, "%s\n", card->cid.prod_name); 508 - MMC_ATTR_FN(oemid, "0x%04x\n", card->cid.oemid); 509 - MMC_ATTR_FN(serial, "0x%08x\n", card->cid.serial); 510 - 511 - static struct device_attribute mmc_dev_attrs[] = { 512 - MMC_ATTR_RO(cid), 513 - MMC_ATTR_RO(csd), 514 - MMC_ATTR_RO(date), 515 - MMC_ATTR_RO(fwrev), 516 - MMC_ATTR_RO(hwrev), 517 - MMC_ATTR_RO(manfid), 518 - MMC_ATTR_RO(name), 519 - MMC_ATTR_RO(oemid), 520 - MMC_ATTR_RO(serial), 521 - __ATTR_NULL, 522 - }; 523 - 524 - /* 525 - * Adds sysfs entries as relevant. 526 - */ 527 - static int mmc_sysfs_add(struct mmc_host *host, struct mmc_card *card) 528 - { 529 - int ret; 530 - 531 - ret = mmc_add_attrs(card, mmc_dev_attrs); 532 - if (ret < 0) 533 - return ret; 534 - 535 - return 0; 536 - } 537 - 538 - /* 539 - * Removes the sysfs entries added by mmc_sysfs_add(). 540 - */ 541 - static void mmc_sysfs_remove(struct mmc_host *host, struct mmc_card *card) 542 - { 543 - mmc_remove_attrs(card, mmc_dev_attrs); 544 - } 545 - 546 462 #ifdef CONFIG_MMC_UNSAFE_RESUME 547 463 548 464 /* ··· 550 560 static const struct mmc_bus_ops mmc_ops = { 551 561 .remove = mmc_remove, 552 562 .detect = mmc_detect, 553 - .sysfs_add = mmc_sysfs_add, 554 - .sysfs_remove = mmc_sysfs_remove, 555 563 .suspend = mmc_suspend, 556 564 .resume = mmc_resume, 557 565 };
+42 -53
drivers/mmc/core/sd.c
··· 18 18 #include <linux/mmc/sd.h> 19 19 20 20 #include "core.h" 21 - #include "sysfs.h" 22 21 #include "bus.h" 23 22 #include "mmc_ops.h" 24 23 #include "sd_ops.h" ··· 282 283 return err; 283 284 } 284 285 286 + MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1], 287 + card->raw_cid[2], card->raw_cid[3]); 288 + MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], 289 + card->raw_csd[2], card->raw_csd[3]); 290 + MMC_DEV_ATTR(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]); 291 + MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); 292 + MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); 293 + MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); 294 + MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); 295 + MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name); 296 + MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid); 297 + MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial); 298 + 299 + 300 + static struct attribute *sd_std_attrs[] = { 301 + &dev_attr_cid.attr, 302 + &dev_attr_csd.attr, 303 + &dev_attr_scr.attr, 304 + &dev_attr_date.attr, 305 + &dev_attr_fwrev.attr, 306 + &dev_attr_hwrev.attr, 307 + &dev_attr_manfid.attr, 308 + &dev_attr_name.attr, 309 + &dev_attr_oemid.attr, 310 + &dev_attr_serial.attr, 311 + NULL, 312 + }; 313 + 314 + static struct attribute_group sd_std_attr_group = { 315 + .attrs = sd_std_attrs, 316 + }; 317 + 318 + static struct attribute_group *sd_attr_groups[] = { 319 + &sd_std_attr_group, 320 + NULL, 321 + }; 322 + 323 + static struct device_type sd_type = { 324 + .groups = sd_attr_groups, 325 + }; 326 + 285 327 /* 286 328 * Handle the detection and initialisation of a card. 287 329 * ··· 392 352 /* 393 353 * Allocate card structure. 394 354 */ 395 - card = mmc_alloc_card(host); 355 + card = mmc_alloc_card(host, &sd_type); 396 356 if (IS_ERR(card)) { 397 357 err = PTR_ERR(card); 398 358 goto err; ··· 558 518 } 559 519 } 560 520 561 - MMC_ATTR_FN(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1], 562 - card->raw_cid[2], card->raw_cid[3]); 563 - MMC_ATTR_FN(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], 564 - card->raw_csd[2], card->raw_csd[3]); 565 - MMC_ATTR_FN(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]); 566 - MMC_ATTR_FN(date, "%02d/%04d\n", card->cid.month, card->cid.year); 567 - MMC_ATTR_FN(fwrev, "0x%x\n", card->cid.fwrev); 568 - MMC_ATTR_FN(hwrev, "0x%x\n", card->cid.hwrev); 569 - MMC_ATTR_FN(manfid, "0x%06x\n", card->cid.manfid); 570 - MMC_ATTR_FN(name, "%s\n", card->cid.prod_name); 571 - MMC_ATTR_FN(oemid, "0x%04x\n", card->cid.oemid); 572 - MMC_ATTR_FN(serial, "0x%08x\n", card->cid.serial); 573 - 574 - static struct device_attribute mmc_sd_dev_attrs[] = { 575 - MMC_ATTR_RO(cid), 576 - MMC_ATTR_RO(csd), 577 - MMC_ATTR_RO(scr), 578 - MMC_ATTR_RO(date), 579 - MMC_ATTR_RO(fwrev), 580 - MMC_ATTR_RO(hwrev), 581 - MMC_ATTR_RO(manfid), 582 - MMC_ATTR_RO(name), 583 - MMC_ATTR_RO(oemid), 584 - MMC_ATTR_RO(serial), 585 - __ATTR_NULL, 586 - }; 587 - 588 - /* 589 - * Adds sysfs entries as relevant. 590 - */ 591 - static int mmc_sd_sysfs_add(struct mmc_host *host, struct mmc_card *card) 592 - { 593 - int ret; 594 - 595 - ret = mmc_add_attrs(card, mmc_sd_dev_attrs); 596 - if (ret < 0) 597 - return ret; 598 - 599 - return 0; 600 - } 601 - 602 - /* 603 - * Removes the sysfs entries added by mmc_sysfs_add(). 604 - */ 605 - static void mmc_sd_sysfs_remove(struct mmc_host *host, struct mmc_card *card) 606 - { 607 - mmc_remove_attrs(card, mmc_sd_dev_attrs); 608 - } 609 - 610 521 #ifdef CONFIG_MMC_UNSAFE_RESUME 611 522 612 523 /* ··· 612 621 static const struct mmc_bus_ops mmc_sd_ops = { 613 622 .remove = mmc_sd_remove, 614 623 .detect = mmc_sd_detect, 615 - .sysfs_add = mmc_sd_sysfs_add, 616 - .sysfs_remove = mmc_sd_sysfs_remove, 617 624 .suspend = mmc_sd_suspend, 618 625 .resume = mmc_sd_resume, 619 626 };
+1 -1
drivers/mmc/core/sdio.c
··· 287 287 /* 288 288 * Allocate card structure. 289 289 */ 290 - card = mmc_alloc_card(host); 290 + card = mmc_alloc_card(host, NULL); 291 291 if (IS_ERR(card)) { 292 292 err = PTR_ERR(card); 293 293 goto err;
-43
drivers/mmc/core/sysfs.c
··· 1 - /* 2 - * linux/drivers/mmc/core/sysfs.c 3 - * 4 - * Copyright (C) 2003 Russell King, All Rights Reserved. 5 - * Copyright 2007 Pierre Ossman 6 - * 7 - * This program is free software; you can redistribute it and/or modify 8 - * it under the terms of the GNU General Public License version 2 as 9 - * published by the Free Software Foundation. 10 - * 11 - * MMC sysfs/driver model support. 12 - */ 13 - #include <linux/device.h> 14 - 15 - #include <linux/mmc/card.h> 16 - 17 - #include "sysfs.h" 18 - 19 - int mmc_add_attrs(struct mmc_card *card, struct device_attribute *attrs) 20 - { 21 - int error = 0; 22 - int i; 23 - 24 - for (i = 0; attr_name(attrs[i]); i++) { 25 - error = device_create_file(&card->dev, &attrs[i]); 26 - if (error) { 27 - while (--i >= 0) 28 - device_remove_file(&card->dev, &attrs[i]); 29 - break; 30 - } 31 - } 32 - 33 - return error; 34 - } 35 - 36 - void mmc_remove_attrs(struct mmc_card *card, struct device_attribute *attrs) 37 - { 38 - int i; 39 - 40 - for (i = 0; attr_name(attrs[i]); i++) 41 - device_remove_file(&card->dev, &attrs[i]); 42 - } 43 -
-26
drivers/mmc/core/sysfs.h
··· 1 - /* 2 - * linux/drivers/mmc/core/sysfs.h 3 - * 4 - * Copyright (C) 2003 Russell King, All Rights Reserved. 5 - * Copyright 2007 Pierre Ossman 6 - * 7 - * This program is free software; you can redistribute it and/or modify 8 - * it under the terms of the GNU General Public License version 2 as 9 - * published by the Free Software Foundation. 10 - */ 11 - #ifndef _MMC_CORE_SYSFS_H 12 - #define _MMC_CORE_SYSFS_H 13 - 14 - #define MMC_ATTR_FN(name, fmt, args...) \ 15 - static ssize_t mmc_##name##_show (struct device *dev, struct device_attribute *attr, char *buf) \ 16 - { \ 17 - struct mmc_card *card = container_of(dev, struct mmc_card, dev);\ 18 - return sprintf(buf, fmt, args); \ 19 - } 20 - 21 - #define MMC_ATTR_RO(name) __ATTR(name, S_IRUGO, mmc_##name##_show, NULL) 22 - 23 - int mmc_add_attrs(struct mmc_card *card, struct device_attribute *attrs); 24 - void mmc_remove_attrs(struct mmc_card *card, struct device_attribute *attrs); 25 - 26 - #endif