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

Configure Feed

Select the types of activity you want to include in your feed.

Input: hycon-hy46xx - use guard notation when acquiring mutex

Guard notation simplifies code.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+11 -20
+11 -20
drivers/input/touchscreen/hycon-hy46xx.c
··· 181 181 struct hycon_hy46xx_attribute *attr = 182 182 container_of(dattr, struct hycon_hy46xx_attribute, dattr); 183 183 u8 *field = (u8 *)tsdata + attr->field_offset; 184 - size_t count = 0; 185 184 int error = 0; 186 185 int val; 187 186 188 - mutex_lock(&tsdata->mutex); 187 + guard(mutex)(&tsdata->mutex); 189 188 190 189 error = regmap_read(tsdata->regmap, attr->address, &val); 191 - if (error < 0) { 190 + if (error) { 192 191 dev_err(&tsdata->client->dev, 193 192 "Failed to fetch attribute %s, error %d\n", 194 193 dattr->attr.name, error); 195 - goto out; 194 + return error; 196 195 } 197 196 198 197 if (val != *field) { ··· 201 202 *field = val; 202 203 } 203 204 204 - count = sysfs_emit(buf, "%d\n", val); 205 - 206 - out: 207 - mutex_unlock(&tsdata->mutex); 208 - return error ?: count; 205 + return sysfs_emit(buf, "%d\n", val); 209 206 } 210 207 211 208 static ssize_t hycon_hy46xx_setting_store(struct device *dev, ··· 216 221 unsigned int val; 217 222 int error; 218 223 219 - mutex_lock(&tsdata->mutex); 224 + guard(mutex)(&tsdata->mutex); 220 225 221 226 error = kstrtouint(buf, 0, &val); 222 227 if (error) 223 - goto out; 228 + return error; 224 229 225 - if (val < attr->limit_low || val > attr->limit_high) { 226 - error = -ERANGE; 227 - goto out; 228 - } 230 + if (val < attr->limit_low || val > attr->limit_high) 231 + return -ERANGE; 229 232 230 233 error = regmap_write(tsdata->regmap, attr->address, val); 231 - if (error < 0) { 234 + if (error) { 232 235 dev_err(&tsdata->client->dev, 233 236 "Failed to update attribute %s, error: %d\n", 234 237 dattr->attr.name, error); 235 - goto out; 238 + return error; 236 239 } 237 240 *field = val; 238 241 239 - out: 240 - mutex_unlock(&tsdata->mutex); 241 - return error ?: count; 242 + return count; 242 243 } 243 244 244 245 static HYCON_ATTR_U8(threshold, 0644, HY46XX_THRESHOLD, 0, 255);