History

EDAC: Introduce an mci_for_each_dimm() iterator

Introduce an mci_for_each_dimm() iterator. It returns a pointer to a struct dimm_info. This makes the declaration and use of an index obsolete and avoids access to internal data of struct mci (direct array access etc). [ bp: push the struct dimm_info *dimm; declaration into the CONFIG_EDAC_DEBUG block. ]

Robert Richter committed 7 years ago

Commit c498afa1 parent 977b1ce5 files · +40 −37Browse files

Unified · Split

5 files
  1. drivers/edac/edac_mc.c +11 −8
  2. drivers/edac/edac_mc_sysfs.c +12 −17
  3. drivers/edac/ghes_edac.c +5 −4
  4. drivers/edac/i5100_edac.c +5 −8
  5. include/linux/edac.h +7 −0
drivers/edac/edac_mc.c+11−8
@@ -145,15 +145,18 @@ static void edac_mc_dump_channel(struct rank_info *chan) · 144 unmodified lines
145145 edac_dbg(4, " channel->dimm = %p\n", chan->dimm);
146146 }
147147
148−static void edac_mc_dump_dimm(struct dimm_info *dimm, int number)
148+static void edac_mc_dump_dimm(struct dimm_info *dimm)
149149 {
150150 char location[80];
151151
152+ if (!dimm->nr_pages)
153+ return;
154+
152155 edac_dimm_info_location(dimm, location, sizeof(location));
153156
154157 edac_dbg(4, "%s%i: %smapped as virtual row %d, chan %d\n",
155158 dimm->mci->csbased ? "rank" : "dimm",
156− number, location, dimm->csrow, dimm->cschannel);
159+ dimm->idx, location, dimm->csrow, dimm->cschannel);
157160 edac_dbg(4, " dimm = %p\n", dimm);
158161 edac_dbg(4, " dimm->label = '%s'\n", dimm->label);
159162 edac_dbg(4, " dimm->nr_pages = 0x%x\n", dimm->nr_pages);
@@ -712,6 +715,7 @@ int edac_mc_add_mc_with_groups(struct mem_ctl_info *mci, · 552 unmodified lines
712715 edac_mc_dump_mci(mci);
713716
714717 if (edac_debug_level >= 4) {
718+ struct dimm_info *dimm;
715719 int i;
716720
717721 for (i = 0; i < mci->nr_csrows; i++) {
@@ -728,9 +732,9 @@ int edac_mc_add_mc_with_groups(struct mem_ctl_info *mci, · 10 unmodified lines
728732 if (csrow->channels[j]->dimm->nr_pages)
729733 edac_mc_dump_channel(csrow->channels[j]);
730734 }
731− for (i = 0; i < mci->tot_dimms; i++)
732− if (mci->dimms[i]->nr_pages)
733− edac_mc_dump_dimm(mci->dimms[i], i);
735+
736+ mci_for_each_dimm(mci, dimm)
737+ edac_mc_dump_dimm(dimm);
734738 }
735739 #endif
736740 mutex_lock(&mem_ctls_mutex);
@@ -1088,6 +1092,7 @@ void edac_mc_handle_error(const enum hw_event_mc_err_type type, · 351 unmodified lines
10881092 const char *msg,
10891093 const char *other_detail)
10901094 {
1095+ struct dimm_info *dimm;
10911096 char *p;
10921097 int row = -1, chan = -1;
10931098 int pos[EDAC_MAX_LAYERS] = { top_layer, mid_layer, low_layer };
@@ -1148,9 +1153,7 @@ void edac_mc_handle_error(const enum hw_event_mc_err_type type, · 54 unmodified lines
11481153 p = e->label;
11491154 *p = '\0';
11501155
1151− for (i = 0; i < mci->tot_dimms; i++) {
1152− struct dimm_info *dimm = mci->dimms[i];
1153−
1156+ mci_for_each_dimm(mci, dimm) {
11541157 if (top_layer >= 0 && top_layer != dimm->location[0])
11551158 continue;
11561159 if (mid_layer >= 0 && mid_layer != dimm->location[1])
drivers/edac/edac_mc_sysfs.c+12−17
@@ -621,8 +621,7 @@ static const struct device_type dimm_attr_type = { · 620 unmodified lines
621621
622622 /* Create a DIMM object under specifed memory controller device */
623623 static int edac_create_dimm_object(struct mem_ctl_info *mci,
624− struct dimm_info *dimm,
625− int index)
624+ struct dimm_info *dimm)
626625 {
627626 int err;
628627 dimm->mci = mci;
@@ -632,9 +631,9 @@ static int edac_create_dimm_object(struct mem_ctl_info *mci, · 3 unmodified lines
632631
633632 dimm->dev.parent = &mci->dev;
634633 if (mci->csbased)
635− dev_set_name(&dimm->dev, "rank%d", index);
634+ dev_set_name(&dimm->dev, "rank%d", dimm->idx);
636635 else
637− dev_set_name(&dimm->dev, "dimm%d", index);
636+ dev_set_name(&dimm->dev, "dimm%d", dimm->idx);
638637 dev_set_drvdata(&dimm->dev, dimm);
639638 pm_runtime_forbid(&mci->dev);
640639
@@ -916,7 +915,8 @@ static const struct device_type mci_attr_type = { · 275 unmodified lines
916915 int edac_create_sysfs_mci_device(struct mem_ctl_info *mci,
917916 const struct attribute_group **groups)
918917 {
919− int i, err;
918+ struct dimm_info *dimm;
919+ int err;
920920
921921 /* get the /sys/devices/system/edac subsys reference */
922922 mci->dev.type = &mci_attr_type;
@@ -940,13 +940,12 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci, · 17 unmodified lines
940940 /*
941941 * Create the dimm/rank devices
942942 */
943− for (i = 0; i < mci->tot_dimms; i++) {
944− struct dimm_info *dimm = mci->dimms[i];
943+ mci_for_each_dimm(mci, dimm) {
945944 /* Only expose populated DIMMs */
946945 if (!dimm->nr_pages)
947946 continue;
948947
949− err = edac_create_dimm_object(mci, dimm, i);
948+ err = edac_create_dimm_object(mci, dimm);
950949 if (err)
951950 goto fail_unregister_dimm;
952951 }
@@ -961,12 +960,9 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci, · 8 unmodified lines
961960 return 0;
962961
963962 fail_unregister_dimm:
964− for (i--; i >= 0; i--) {
965− struct dimm_info *dimm = mci->dimms[i];
966− if (!dimm->nr_pages)
967− continue;
968−
969− device_unregister(&dimm->dev);
963+ mci_for_each_dimm(mci, dimm) {
964+ if (device_is_registered(&dimm->dev))
965+ device_unregister(&dimm->dev);
970966 }
971967 device_unregister(&mci->dev);
972968
@@ -978,7 +974,7 @@ fail_unregister_dimm: · 5 unmodified lines
978974 */
979975 void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
980976 {
981− int i;
977+ struct dimm_info *dimm;
982978
983979 edac_dbg(0, "\n");
984980
@@ -989,8 +985,7 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci) · 4 unmodified lines
989985 edac_delete_csrow_objects(mci);
990986 #endif
991987
992− for (i = 0; i < mci->tot_dimms; i++) {
993− struct dimm_info *dimm = mci->dimms[i];
988+ mci_for_each_dimm(mci, dimm) {
994989 if (dimm->nr_pages == 0)
995990 continue;
996991 edac_dbg(1, "unregistering device %s\n", dev_name(&dimm->dev));
drivers/edac/ghes_edac.c+5−4
@@ -90,12 +90,13 @@ static void ghes_edac_count_dimms(const struct dmi_header *dh, void *arg) · 89 unmodified lines
9090
9191 static int get_dimm_smbios_index(struct mem_ctl_info *mci, u16 handle)
9292 {
93− int i;
93+ struct dimm_info *dimm;
9494
95− for (i = 0; i < mci->tot_dimms; i++) {
96− if (mci->dimms[i]->smbios_handle == handle)
97− return i;
95+ mci_for_each_dimm(mci, dimm) {
96+ if (dimm->smbios_handle == handle)
97+ return dimm->idx;
9898 }
99+
99100 return -1;
100101 }
101102
drivers/edac/i5100_edac.c+5−8
@@ -846,20 +846,17 @@ static void i5100_init_interleaving(struct pci_dev *pdev, · 845 unmodified lines
846846
847847 static void i5100_init_csrows(struct mem_ctl_info *mci)
848848 {
849− int i;
850849 struct i5100_priv *priv = mci->pvt_info;
850+ struct dimm_info *dimm;
851851
852− for (i = 0; i < mci->tot_dimms; i++) {
853− struct dimm_info *dimm;
854− const unsigned long npages = i5100_npages(mci, i);
855− const unsigned int chan = i5100_csrow_to_chan(mci, i);
856− const unsigned int rank = i5100_csrow_to_rank(mci, i);
852+ mci_for_each_dimm(mci, dimm) {
853+ const unsigned long npages = i5100_npages(mci, dimm->idx);
854+ const unsigned int chan = i5100_csrow_to_chan(mci, dimm->idx);
855+ const unsigned int rank = i5100_csrow_to_rank(mci, dimm->idx);
857856
858857 if (!npages)
859858 continue;
860859
861− dimm = edac_get_dimm(mci, chan, rank, 0);
862−
863860 dimm->nr_pages = npages;
864861 dimm->grain = 32;
865862 dimm->dtype = (priv->mtr[chan][rank].width == 4) ?
include/linux/edac.h+7−0
@@ -599,6 +599,13 @@ struct mem_ctl_info { · 598 unmodified lines
599599 u16 fake_inject_count;
600600 };
601601
602+#define mci_for_each_dimm(mci, dimm) \
603+ for ((dimm) = (mci)->dimms[0]; \
604+ (dimm); \
605+ (dimm) = (dimm)->idx + 1 < (mci)->tot_dimms \
606+ ? (mci)->dimms[(dimm)->idx + 1] \
607+ : NULL)
608+
602609 /**
603610 * edac_get_dimm_by_index - Get DIMM info at @index from a memory
604611 * controller

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t