Skip to contentSkip to conversation

ni_routing: Check when the file could not be opened

PATCH Superseded Ruffalo Lavoisier 2 participants 2 messages Sep 6, 2024 Comedi drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ni_routing: Check when the file could not be opened

---
 drivers/comedi/drivers/ni_routing/tools/convert_c_to_py.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/comedi/drivers/ni_routing/tools/convert_c_to_py.c +4 -0
index d55521b5bdcb..d0321a7565c5 100644
@@ -139,6 +139,10 @@ void device_write(const struct ni_device_routes *dR, FILE *fp)
 int main(void)
 {
 	FILE *fp = fopen("ni_values.py", "w");
+	if (fp == NULL) {
+		fprintf(stderr, "Could not open file!");
+		return -1;
+	}
 
 	/* write route register values */
 	fprintf(fp, "ni_route_values = {\n");
Signature · 1 line
2.43.0
#1 lore raw
Quoted 1 line · Ruffalo Lavoisier

For obvious reasons, we can't take patches without a changelog :(

Quoted 9 lines
---
 drivers/comedi/drivers/ni_routing/tools/convert_c_to_py.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/comedi/drivers/ni_routing/tools/convert_c_to_py.c +0 -0
index d55521b5bdcb..d0321a7565c5 100644

drivers/comedi/drivers/ni_routing/tools/convert_c_to_py.c void device_write(const struct ni_device_routes *dR, FILE *fp) · line 145

Quoted 7 lines
drivers/comedi/drivers/ni_routing/tools/convert_c_to_py.c +4 -0
@@ -139,6 +139,10 @@ void device_write(const struct ni_device_routes *dR, FILE *fp)
 int main(void)
 {
 	FILE *fp = fopen("ni_values.py", "w");
+	if (fp == NULL) {
+		fprintf(stderr, "Could not open file!");
+		return -1;
+	}

Did you run this through checkpatch.pl? I think you need a blank line before your check.

And is this fixing a real-world issue, or just something you noticed?

thanks,

greg k-h