Skip to content

Commit

Permalink
docs: stop suggesting strlcpy
Browse files Browse the repository at this point in the history
Since strlcpy is deprecated, the documentation shouldn't suggest using
it. This patch fixes the examples to use strscpy instead. It also uses
sizeof instead of underlying constants as far as possible, to simplify
future changes to the corresponding data structures.

Signed-off-by: Stephen Kitt <steve@sk2.org>
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Federico Vaga <federico.vaga@vaga.pv.it>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
  • Loading branch information
skitt authored and Jonathan Corbet committed Jun 20, 2019
1 parent 4ae5b8f commit 220ee02
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Documentation/hid/hid-transport.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ with HID core:
goto err_<...>;
}

strlcpy(hid->name, <device-name-src>, 127);
strlcpy(hid->phys, <device-phys-src>, 63);
strlcpy(hid->uniq, <device-uniq-src>, 63);
strscpy(hid->name, <device-name-src>, sizeof(hid->name));
strscpy(hid->phys, <device-phys-src>, sizeof(hid->phys));
strscpy(hid->uniq, <device-uniq-src>, sizeof(hid->uniq));

hid->ll_driver = &custom_ll_driver;
hid->bus = <device-bus>;
Expand Down
2 changes: 1 addition & 1 deletion Documentation/i2c/instantiating-devices
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static int usb_hcd_nxp_probe(struct platform_device *pdev)
(...)
i2c_adap = i2c_get_adapter(2);
memset(&i2c_info, 0, sizeof(struct i2c_board_info));
strlcpy(i2c_info.type, "isp1301_nxp", I2C_NAME_SIZE);
strscpy(i2c_info.type, "isp1301_nxp", sizeof(i2c_info.type));
isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info,
normal_i2c, NULL);
i2c_put_adapter(i2c_adap);
Expand Down
4 changes: 2 additions & 2 deletions Documentation/i2c/upgrading-clients
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static int example_attach(struct i2c_adapter *adap, int addr, int kind)
example->client.adapter = adap;

i2c_set_clientdata(&state->i2c_client, state);
strlcpy(client->i2c_client.name, "example", I2C_NAME_SIZE);
strscpy(client->i2c_client.name, "example", sizeof(client->i2c_client.name));

ret = i2c_attach_client(&state->i2c_client);
if (ret < 0) {
Expand Down Expand Up @@ -138,7 +138,7 @@ can be removed:
- example->client.flags = 0;
- example->client.adapter = adap;
-
- strlcpy(client->i2c_client.name, "example", I2C_NAME_SIZE);
- strscpy(client->i2c_client.name, "example", sizeof(client->i2c_client.name));

The i2c_set_clientdata is now:

Expand Down
6 changes: 3 additions & 3 deletions Documentation/kernel-hacking/locking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ to protect the cache and all the objects within it. Here's the code::
if ((obj = kmalloc(sizeof(*obj), GFP_KERNEL)) == NULL)
return -ENOMEM;

strlcpy(obj->name, name, sizeof(obj->name));
strscpy(obj->name, name, sizeof(obj->name));
obj->id = id;
obj->popularity = 0;

Expand Down Expand Up @@ -660,7 +660,7 @@ Here is the code::
}

@@ -63,6 +94,7 @@
strlcpy(obj->name, name, sizeof(obj->name));
strscpy(obj->name, name, sizeof(obj->name));
obj->id = id;
obj->popularity = 0;
+ obj->refcnt = 1; /* The cache holds a reference */
Expand Down Expand Up @@ -774,7 +774,7 @@ the lock is no longer used to protect the reference count itself.
}

@@ -94,7 +76,7 @@
strlcpy(obj->name, name, sizeof(obj->name));
strscpy(obj->name, name, sizeof(obj->name));
obj->id = id;
obj->popularity = 0;
- obj->refcnt = 1; /* The cache holds a reference */
Expand Down
6 changes: 3 additions & 3 deletions Documentation/translations/it_IT/kernel-hacking/locking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ e tutti gli oggetti che contiene. Ecco il codice::
if ((obj = kmalloc(sizeof(*obj), GFP_KERNEL)) == NULL)
return -ENOMEM;

strlcpy(obj->name, name, sizeof(obj->name));
strscpy(obj->name, name, sizeof(obj->name));
obj->id = id;
obj->popularity = 0;

Expand Down Expand Up @@ -678,7 +678,7 @@ Ecco il codice::
}

@@ -63,6 +94,7 @@
strlcpy(obj->name, name, sizeof(obj->name));
strscpy(obj->name, name, sizeof(obj->name));
obj->id = id;
obj->popularity = 0;
+ obj->refcnt = 1; /* The cache holds a reference */
Expand Down Expand Up @@ -792,7 +792,7 @@ contatore stesso.
}

@@ -94,7 +76,7 @@
strlcpy(obj->name, name, sizeof(obj->name));
strscpy(obj->name, name, sizeof(obj->name));
obj->id = id;
obj->popularity = 0;
- obj->refcnt = 1; /* The cache holds a reference */
Expand Down

0 comments on commit 220ee02

Please sign in to comment.