hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/watchdog/ts4800_wdt.c
....@@ -108,7 +108,8 @@
108108
109109 static int ts4800_wdt_probe(struct platform_device *pdev)
110110 {
111
- struct device_node *np = pdev->dev.of_node;
111
+ struct device *dev = &pdev->dev;
112
+ struct device_node *np = dev->of_node;
112113 struct device_node *syscon_np;
113114 struct watchdog_device *wdd;
114115 struct ts4800_wdt *wdt;
....@@ -117,32 +118,36 @@
117118
118119 syscon_np = of_parse_phandle(np, "syscon", 0);
119120 if (!syscon_np) {
120
- dev_err(&pdev->dev, "no syscon property\n");
121
+ dev_err(dev, "no syscon property\n");
121122 return -ENODEV;
122123 }
123124
124125 ret = of_property_read_u32_index(np, "syscon", 1, &reg);
125126 if (ret < 0) {
126
- dev_err(&pdev->dev, "no offset in syscon\n");
127
+ dev_err(dev, "no offset in syscon\n");
128
+ of_node_put(syscon_np);
127129 return ret;
128130 }
129131
130132 /* allocate memory for watchdog struct */
131
- wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
132
- if (!wdt)
133
+ wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
134
+ if (!wdt) {
135
+ of_node_put(syscon_np);
133136 return -ENOMEM;
137
+ }
134138
135139 /* set regmap and offset to know where to write */
136140 wdt->feed_offset = reg;
137141 wdt->regmap = syscon_node_to_regmap(syscon_np);
142
+ of_node_put(syscon_np);
138143 if (IS_ERR(wdt->regmap)) {
139
- dev_err(&pdev->dev, "cannot get parent's regmap\n");
144
+ dev_err(dev, "cannot get parent's regmap\n");
140145 return PTR_ERR(wdt->regmap);
141146 }
142147
143148 /* Initialize struct watchdog_device */
144149 wdd = &wdt->wdd;
145
- wdd->parent = &pdev->dev;
150
+ wdd->parent = dev;
146151 wdd->info = &ts4800_wdt_info;
147152 wdd->ops = &ts4800_wdt_ops;
148153 wdd->min_timeout = ts4800_wdt_map[0].timeout;
....@@ -150,7 +155,7 @@
150155
151156 watchdog_set_drvdata(wdd, wdt);
152157 watchdog_set_nowayout(wdd, nowayout);
153
- watchdog_init_timeout(wdd, 0, &pdev->dev);
158
+ watchdog_init_timeout(wdd, 0, dev);
154159
155160 /*
156161 * As this watchdog supports only a few values, ts4800_wdt_set_timeout
....@@ -168,27 +173,14 @@
168173 */
169174 ts4800_wdt_stop(wdd);
170175
171
- ret = watchdog_register_device(wdd);
172
- if (ret) {
173
- dev_err(&pdev->dev,
174
- "failed to register watchdog device\n");
176
+ ret = devm_watchdog_register_device(dev, wdd);
177
+ if (ret)
175178 return ret;
176
- }
177179
178180 platform_set_drvdata(pdev, wdt);
179181
180
- dev_info(&pdev->dev,
181
- "initialized (timeout = %d sec, nowayout = %d)\n",
182
+ dev_info(dev, "initialized (timeout = %d sec, nowayout = %d)\n",
182183 wdd->timeout, nowayout);
183
-
184
- return 0;
185
-}
186
-
187
-static int ts4800_wdt_remove(struct platform_device *pdev)
188
-{
189
- struct ts4800_wdt *wdt = platform_get_drvdata(pdev);
190
-
191
- watchdog_unregister_device(&wdt->wdd);
192184
193185 return 0;
194186 }
....@@ -201,7 +193,6 @@
201193
202194 static struct platform_driver ts4800_wdt_driver = {
203195 .probe = ts4800_wdt_probe,
204
- .remove = ts4800_wdt_remove,
205196 .driver = {
206197 .name = "ts4800_wdt",
207198 .of_match_table = ts4800_wdt_of_match,