Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: ks7010: move hw info into dev private data

Currently driver uses a hardware information struct description to
group some SDIO related functionality (work, work queue, sdio private
data pointer). This structure is then embedded in the device private
data structure. Having nested structures described in different header
files means that to view the device private data programmers must open
two header files. This structure could be embedded anonymously in the
device private data and achieve the same result (grouping of function
specific to SDIO) without the need to open multiple headers. However,
the SDIO private data structure already has various different data and
pointers, adding the embedded structure adds little extra meaning and
lengthens all the dereferences throughout the driver, often meaning
addition line breaks and braces. We can increase readability and
reduce code complexity by moving the hardware information data and
pointers to directly be within the device private data structure
description.

While preparing for this refactoring it was noted that the identifier
currently used for the delayed work is 'rw_wq', this is confusing
since the 'wq' suffix typically means 'work queue'. This identifier
would be more meaningful if it used the suffix 'dwork' as does the
declaration of queue_delayed_work() (include/linux/workqueue.h).

The identifier for the work queue is currently 'ks7010sdio_wq'. This
identifier can be shortened without loss of meaning because there is
only one work queue within the driver. Identifier 'wq' is typical
within in-tree driver code and aptly describes the pointer.

Current pointer to the SDIO private data is identified by 'sdio_card',
this is sufficiently meaningful from within the hw_info structure but
once the hw_info_t structure is removed the pointer would be better to
have a prefix appended to it to retain the prior level of meaning.

Move members from struct hw_info_t to struct ks_wlan_private.

Rename identifiers;
struct delayed_work pointer 'rw_wq' to 'rw_dwork'.
struct workqueue_struct pointer 'ks7010sdio_wq' to 'wq'.
struct ks_sdio_card pointer 'sdio_card' to 'ks_sdio_card'.

Remove structure description hw_info_t. Fix init/destroy calls. Fix
all call sites, SDIO private data access calls, and queuing calls.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Tobin C. Harding and committed by
Greg Kroah-Hartman
18bd6dd1 321dabdc

+34 -53
+28 -42
drivers/staging/ks7010/ks7010_sdio.c
··· 54 54 struct ks_sdio_card *card; 55 55 int ret; 56 56 57 - card = priv->ks_wlan_hw.sdio_card; 57 + card = priv->ks_sdio_card; 58 58 59 59 if (length == 1) /* CMD52 */ 60 60 *buffer = sdio_readb(card->func, address, &ret); ··· 75 75 struct ks_sdio_card *card; 76 76 int ret; 77 77 78 - card = priv->ks_wlan_hw.sdio_card; 78 + card = priv->ks_sdio_card; 79 79 80 80 if (length == 1) /* CMD52 */ 81 81 sdio_writeb(card->func, *buffer, address, &ret); ··· 198 198 if (atomic_read(&priv->psstatus.confirm_wait) || 199 199 atomic_read(&priv->psstatus.snooze_guard) || 200 200 cnt_txqbody(priv)) { 201 - queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq, 202 - &priv->ks_wlan_hw.rw_wq, 0); 201 + queue_delayed_work(priv->wq, &priv->rw_dwork, 0); 203 202 return; 204 203 } 205 204 ··· 223 224 return; 224 225 225 226 queue_delayed_work: 226 - queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq, 227 - &priv->ks_wlan_hw.rw_wq, 1); 227 + queue_delayed_work(priv->wq, &priv->rw_dwork, 1); 228 228 } 229 229 230 230 int ks_wlan_hw_power_save(struct ks_wlan_private *priv) 231 231 { 232 - queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq, 233 - &priv->ks_wlan_hw.rw_wq, 1); 232 + queue_delayed_work(priv->wq, &priv->rw_dwork, 1); 234 233 return 0; 235 234 } 236 235 ··· 317 320 ret = write_to_device(priv, sp->sendp, sp->size); 318 321 if (ret) { 319 322 DPRINTK(1, "write_to_device error !!(%d)\n", ret); 320 - queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq, 321 - &priv->ks_wlan_hw.rw_wq, 1); 323 + queue_delayed_work(priv->wq, &priv->rw_dwork, 1); 322 324 return; 323 325 } 324 326 } ··· 326 330 (*sp->complete_handler)(priv, sp->skb); 327 331 inc_txqhead(priv); 328 332 329 - if (cnt_txqbody(priv) > 0) { 330 - queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq, 331 - &priv->ks_wlan_hw.rw_wq, 0); 332 - } 333 + if (cnt_txqbody(priv) > 0) 334 + queue_delayed_work(priv->wq, &priv->rw_dwork, 0); 333 335 } 334 336 335 337 int ks_wlan_hw_tx(struct ks_wlan_private *priv, void *p, unsigned long size, ··· 354 360 result = enqueue_txdev(priv, p, size, complete_handler, skb); 355 361 spin_unlock(&priv->tx_dev.tx_dev_lock); 356 362 357 - if (cnt_txqbody(priv) > 0) { 358 - queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq, 359 - &priv->ks_wlan_hw.rw_wq, 0); 360 - } 363 + if (cnt_txqbody(priv) > 0) 364 + queue_delayed_work(priv->wq, &priv->rw_dwork, 0); 365 + 361 366 return result; 362 367 } 363 368 ··· 445 452 446 453 static void ks7010_rw_function(struct work_struct *work) 447 454 { 448 - struct hw_info_t *hw; 449 455 struct ks_wlan_private *priv; 450 456 unsigned char rw_data; 451 457 int ret; 452 458 453 - hw = container_of(work, struct hw_info_t, rw_wq.work); 454 - priv = container_of(hw, struct ks_wlan_private, ks_wlan_hw); 459 + priv = container_of(work, struct ks_wlan_private, rw_dwork.work); 455 460 456 461 DPRINTK(4, "\n"); 457 462 458 463 /* wiat after DOZE */ 459 464 if (time_after(priv->last_doze + ((30 * HZ) / 1000), jiffies)) { 460 465 DPRINTK(4, "wait after DOZE\n"); 461 - queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq, 462 - &priv->ks_wlan_hw.rw_wq, 1); 466 + queue_delayed_work(priv->wq, &priv->rw_dwork, 1); 463 467 return; 464 468 } 465 469 466 470 /* wiat after WAKEUP */ 467 471 while (time_after(priv->last_wakeup + ((30 * HZ) / 1000), jiffies)) { 468 472 DPRINTK(4, "wait after WAKEUP\n"); 469 - dev_info(&priv->ks_wlan_hw.sdio_card->func->dev, 473 + dev_info(&priv->ks_sdio_card->func->dev, 470 474 "wake: %lu %lu\n", 471 475 priv->last_wakeup + (30 * HZ) / 1000, 472 476 jiffies); 473 477 msleep(30); 474 478 } 475 479 476 - sdio_claim_host(priv->ks_wlan_hw.sdio_card->func); 480 + sdio_claim_host(priv->ks_sdio_card->func); 477 481 478 482 /* power save wakeup */ 479 483 if (atomic_read(&priv->psstatus.status) == PS_SNOOZE) { 480 484 if (cnt_txqbody(priv) > 0) { 481 485 ks_wlan_hw_wakeup_request(priv); 482 - queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq, 483 - &priv->ks_wlan_hw.rw_wq, 1); 486 + queue_delayed_work(priv->wq, &priv->rw_dwork, 1); 484 487 } 485 488 goto err_release_host; 486 489 } ··· 510 521 _ks_wlan_hw_power_save(priv); 511 522 512 523 err_release_host: 513 - sdio_release_host(priv->ks_wlan_hw.sdio_card->func); 524 + sdio_release_host(priv->ks_sdio_card->func); 514 525 } 515 526 516 527 static void ks_sdio_interrupt(struct sdio_func *func) ··· 573 584 if (atomic_read(&priv->psstatus.status) == PS_SNOOZE) { 574 585 if (cnt_txqbody(priv)) { 575 586 ks_wlan_hw_wakeup_request(priv); 576 - queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq, 577 - &priv->ks_wlan_hw.rw_wq, 1); 587 + queue_delayed_work(priv->wq, &priv->rw_dwork, 1); 578 588 return; 579 589 } 580 590 } else { ··· 583 595 } while (rsize); 584 596 585 597 queue_delayed_work: 586 - queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq, 587 - &priv->ks_wlan_hw.rw_wq, 0); 598 + queue_delayed_work(priv->wq, &priv->rw_dwork, 0); 588 599 } 589 600 590 601 static int trx_device_init(struct ks_wlan_private *priv) ··· 701 714 } 702 715 703 716 ret = request_firmware(&fw_entry, ROM_FILE, 704 - &priv->ks_wlan_hw.sdio_card->func->dev); 717 + &priv->ks_sdio_card->func->dev); 705 718 if (ret) 706 719 goto release_host_and_free; 707 720 ··· 936 949 SET_NETDEV_DEV(netdev, &card->func->dev); /* for create sysfs symlinks */ 937 950 938 951 /* private memory initialize */ 939 - priv->ks_wlan_hw.sdio_card = card; 952 + priv->ks_sdio_card = card; 940 953 941 954 priv->dev_state = DEVICE_STATE_PREBOOT; 942 955 priv->net_dev = netdev; ··· 988 1001 DPRINTK(4, " enable Interrupt : INT_ENABLE=%02X\n", rw_data); 989 1002 priv->dev_state = DEVICE_STATE_BOOT; 990 1003 991 - priv->ks_wlan_hw.ks7010sdio_wq = create_workqueue("ks7010sdio_wq"); 992 - if (!priv->ks_wlan_hw.ks7010sdio_wq) { 1004 + priv->wq = create_workqueue("wq"); 1005 + if (!priv->wq) { 993 1006 DPRINTK(1, "create_workqueue failed !!\n"); 994 1007 goto err_free_netdev; 995 1008 } 996 1009 997 - INIT_DELAYED_WORK(&priv->ks_wlan_hw.rw_wq, ks7010_rw_function); 1010 + INIT_DELAYED_WORK(&priv->rw_dwork, ks7010_rw_function); 998 1011 ks7010_card_init(priv); 999 1012 1000 1013 ret = register_netdev(priv->net_dev); ··· 1082 1095 1083 1096 DPRINTK(1, "STOP Req\n"); 1084 1097 1085 - if (priv->ks_wlan_hw.ks7010sdio_wq) { 1086 - flush_workqueue(priv->ks_wlan_hw.ks7010sdio_wq); 1087 - destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq); 1098 + if (priv->wq) { 1099 + flush_workqueue(priv->wq); 1100 + destroy_workqueue(priv->wq); 1088 1101 } 1089 - DPRINTK(1, 1090 - "destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);\n"); 1102 + DPRINTK(1, "destroy_workqueue(priv->wq);\n"); 1091 1103 1092 1104 hostif_exit(priv); 1093 1105 DPRINTK(1, "hostif_exit\n");
-6
drivers/staging/ks7010/ks7010_sdio.h
··· 85 85 86 86 #define KS7010_IRAM_ADDRESS 0x06000000 87 87 88 - struct hw_info_t { 89 - struct ks_sdio_card *sdio_card; 90 - struct workqueue_struct *ks7010sdio_wq; 91 - struct delayed_work rw_wq; 92 - }; 93 - 94 88 struct ks_sdio_card { 95 89 struct sdio_func *func; 96 90 struct ks_wlan_private *priv;
+2 -4
drivers/staging/ks7010/ks_hostif.c
··· 743 743 DPRINTK(3, "\n"); 744 744 745 745 atomic_set(&priv->sleepstatus.doze_request, 1); 746 - queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq, 747 - &priv->ks_wlan_hw.rw_wq, 1); 746 + queue_delayed_work(priv->wq, &priv->rw_dwork, 1); 748 747 } 749 748 750 749 static ··· 1744 1745 NULL); 1745 1746 } else if (mode == SLP_ACTIVE) { 1746 1747 atomic_set(&priv->sleepstatus.wakeup_request, 1); 1747 - queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq, 1748 - &priv->ks_wlan_hw.rw_wq, 1); 1748 + queue_delayed_work(priv->wq, &priv->rw_dwork, 1); 1749 1749 } else { 1750 1750 DPRINTK(3, "invalid mode %ld\n", mode); 1751 1751 return;
+4 -1
drivers/staging/ks7010/ks_wlan.h
··· 413 413 #endif /* WPS */ 414 414 415 415 struct ks_wlan_private { 416 - struct hw_info_t ks_wlan_hw; /* hardware information */ 416 + /* hardware information */ 417 + struct ks_sdio_card *ks_sdio_card; 418 + struct workqueue_struct *wq; 419 + struct delayed_work rw_dwork; 417 420 struct tasklet_struct rx_bh_task; 418 421 419 422 struct net_device *net_dev;