Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1705019 > unrolled thread
| Started by | Christophe JAILLET <christophe.jaillet@wanadoo.fr> |
|---|---|
| First post | 2017-08-07 00:40 +0200 |
| Last post | 2017-08-07 10:50 +0200 |
| Articles | 4 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH 0/3] power: supply: charger-manager: 1 fix and 2 minor clean-ups Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-08-07 00:40 +0200
[PATCH] scsi: mpt3sas: Fix memory allocation failure test in 'mpt3sas_base_attach()' Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-08-07 01:00 +0200
Re: [PATCH] scsi: mpt3sas: Fix memory allocation failure test in 'mpt3sas_base_attach()' walter harms <wharms@bfs.de> - 2017-08-07 10:30 +0200
Re: [PATCH] scsi: mpt3sas: Fix memory allocation failure test in 'mpt3sas_base_attach()' Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-08-07 10:50 +0200
| From | Christophe JAILLET <christophe.jaillet@wanadoo.fr> |
|---|---|
| Date | 2017-08-07 00:40 +0200 |
| Subject | [PATCH 0/3] power: supply: charger-manager: 1 fix and 2 minor clean-ups |
| Message-ID | <ubCnf-893-5@gated-at.bofh.it> |
This patch series improves 'charger_manager_probe()'. The first patch is
about a missing memory allocation failure test.
The 2 others are just things spotted in this function:
- a comment that is no more up to date
- a style issue (which saves 1 line)
Christophe JAILLET (3):
power: supply: charger-manager: Fix a NULL pointer dereference in
'charger_manager_probe()'
power: supply: charger-manager: Fix a comment
power: supply: charger-manager: Slighly simplify code
drivers/power/supply/charger-manager.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
--
2.11.0
[toc] | [next] | [standalone]
| From | Christophe JAILLET <christophe.jaillet@wanadoo.fr> |
|---|---|
| Date | 2017-08-07 01:00 +0200 |
| Subject | [PATCH] scsi: mpt3sas: Fix memory allocation failure test in 'mpt3sas_base_attach()' |
| Message-ID | <ubCGH-8kV-71@gated-at.bofh.it> |
| In reply to | #1705019 |
In the lines above this test, 8 'kzalloc' are performed, but only 7 results
are tested.
Add the missing one (i.e. '!ioc->port_enable_cmds.reply').
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/scsi/mpt3sas/mpt3sas_base.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 1a5b6e40fb5c..8a44636ab0b5 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -5494,10 +5494,10 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
mutex_init(&ioc->ctl_cmds.mutex);
- if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
- !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
- !ioc->config_cmds.reply || !ioc->ctl_cmds.reply ||
- !ioc->ctl_cmds.sense) {
+ if (!ioc->base_cmds.reply || !ioc->port_enable_cmds.reply ||
+ !ioc->transport_cmds.reply || !ioc->scsih_cmds.reply ||
+ !ioc->tm_cmds.reply || !ioc->config_cmds.reply ||
+ !ioc->ctl_cmds.reply || !ioc->ctl_cmds.sense) {
r = -ENOMEM;
goto out_free_resources;
}
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | walter harms <wharms@bfs.de> |
|---|---|
| Date | 2017-08-07 10:30 +0200 |
| Subject | Re: [PATCH] scsi: mpt3sas: Fix memory allocation failure test in 'mpt3sas_base_attach()' |
| Message-ID | <ubLAe-5Ov-7@gated-at.bofh.it> |
| In reply to | #1705022 |
Am 07.08.2017 00:51, schrieb Christophe JAILLET:
> In the lines above this test, 8 'kzalloc' are performed, but only 7 results
> are tested.
>
> Add the missing one (i.e. '!ioc->port_enable_cmds.reply').
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> drivers/scsi/mpt3sas/mpt3sas_base.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
> index 1a5b6e40fb5c..8a44636ab0b5 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
> @@ -5494,10 +5494,10 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
> ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
> mutex_init(&ioc->ctl_cmds.mutex);
>
> - if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
> - !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
> - !ioc->config_cmds.reply || !ioc->ctl_cmds.reply ||
> - !ioc->ctl_cmds.sense) {
> + if (!ioc->base_cmds.reply || !ioc->port_enable_cmds.reply ||
> + !ioc->transport_cmds.reply || !ioc->scsih_cmds.reply ||
> + !ioc->tm_cmds.reply || !ioc->config_cmds.reply ||
> + !ioc->ctl_cmds.reply || !ioc->ctl_cmds.sense) {
> r = -ENOMEM;
> goto out_free_resources;
> }
obviously it is better to follow the pattern "malloc() , check".
Even the programmer lost track.
Bonus points if you malloc the buffers in one step.
just my 2 cents,
re,
wh
[toc] | [prev] | [next] | [standalone]
| From | Christophe JAILLET <christophe.jaillet@wanadoo.fr> |
|---|---|
| Date | 2017-08-07 10:50 +0200 |
| Subject | Re: [PATCH] scsi: mpt3sas: Fix memory allocation failure test in 'mpt3sas_base_attach()' |
| Message-ID | <ubLTA-5V4-25@gated-at.bofh.it> |
| In reply to | #1705229 |
Le 07/08/2017 à 10:25, walter harms a écrit :
>
> Am 07.08.2017 00:51, schrieb Christophe JAILLET:
>> In the lines above this test, 8 'kzalloc' are performed, but only 7 results
>> are tested.
>>
>> Add the missing one (i.e. '!ioc->port_enable_cmds.reply').
>>
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> drivers/scsi/mpt3sas/mpt3sas_base.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
>> index 1a5b6e40fb5c..8a44636ab0b5 100644
>> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
>> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
>> @@ -5494,10 +5494,10 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
>> ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
>> mutex_init(&ioc->ctl_cmds.mutex);
>>
>> - if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
>> - !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
>> - !ioc->config_cmds.reply || !ioc->ctl_cmds.reply ||
>> - !ioc->ctl_cmds.sense) {
>> + if (!ioc->base_cmds.reply || !ioc->port_enable_cmds.reply ||
>> + !ioc->transport_cmds.reply || !ioc->scsih_cmds.reply ||
>> + !ioc->tm_cmds.reply || !ioc->config_cmds.reply ||
>> + !ioc->ctl_cmds.reply || !ioc->ctl_cmds.sense) {
>> r = -ENOMEM;
>> goto out_free_resources;
>> }
>
> obviously it is better to follow the pattern "malloc() , check".
Agreed, but it is also more verbose. Leavig it as-is, is IMHO, good enough.
> Even the programmer lost track.
>
> Bonus points if you malloc the buffers in one step.
Most of the allocation are 'kzalloc(ioc->reply_sz, GFP_KERNEL);', so a
kcalloc could be used instead.
However, the 'kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);' breaks this
logic and allocating all at once would lead to spaghetti code for no reason.
Moreover, I don't have any idea how big can be 'ioc->reply_sz', even if
I guess it should be small.
So allocating all at once, could fail where several steps would work.
So I won't play for the bonus points :).
Best regards.
CJ
> just my 2 cents,
>
> re,
> wh
>
>
>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web