When communicating with stratix10-svc driver, intel-fcs driver
allocates struct intel_fcs_dev_ioctl and struct stratix10_svc_client_msg
instances with devm_kzalloc function. This causes memory waste, because
memory is allocated every time when communicating with stratix10-svc
driver and it is linked to a list chain of device. In this way, the memory
stress test may cause out ot memory panic.
In consideration of code reuse feature by multiple processes at the same
time, not allocate struct intel_fcs_dev_ioctl and struct 
stratix10_svc_client_msg
instances as global variable, but define local variable to avoid wasting
memory. In consideration of the later sdk patches for this driver, the pointer
variables are not replaced one by one, only define new local variable and then
assign to pointer.

Signed-off-by: Meng Li <[email protected]>
---
 drivers/crypto/intel_fcs.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/drivers/crypto/intel_fcs.c b/drivers/crypto/intel_fcs.c
index 6b3eada08abf..b1d0e501a370 100644
--- a/drivers/crypto/intel_fcs.c
+++ b/drivers/crypto/intel_fcs.c
@@ -252,9 +252,11 @@ static long fcs_ioctl(struct file *file, unsigned int cmd,
                      unsigned long arg)
 {
        struct intel_fcs_dev_ioctl *data;
+       struct intel_fcs_dev_ioctl data_var;
        struct intel_fcs_priv *priv;
        struct device *dev;
        struct stratix10_svc_client_msg *msg;
+       struct stratix10_svc_client_msg msg_var;
        const struct firmware *fw;
        char filename[FILE_NAME_SIZE];
        size_t tsz, rsz, datasz, ud_sz;
@@ -272,14 +274,8 @@ static long fcs_ioctl(struct file *file, unsigned int cmd,
 
        priv = container_of(file->private_data, struct intel_fcs_priv, miscdev);
        dev = priv->client.dev;
-
-       data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
-       if (!data)
-               return -ENOMEM;
-
-       msg = devm_kzalloc(dev, sizeof(*msg), GFP_KERNEL);
-       if (!msg)
-               return -ENOMEM;
+       data = &data_var;
+       msg = &msg_var;
 
        switch (cmd) {
        case INTEL_FCS_DEV_VALIDATION_REQUEST:
@@ -468,7 +464,6 @@ static long fcs_ioctl(struct file *file, unsigned int cmd,
                        dev_err(dev, "failed to allocate RNG buffer\n");
                        return -ENOMEM;
                }
-
                msg->command = COMMAND_FCS_RANDOM_NUMBER_GEN;
                msg->payload = s_buf;
                msg->payload_length = RANDOM_NUMBER_SIZE;
@@ -2460,6 +2455,7 @@ static int fcs_close(struct inode *inode, struct file 
*file)
 static int fcs_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
 {
        struct stratix10_svc_client_msg *msg;
+       struct stratix10_svc_client_msg msg_var;
        struct intel_fcs_priv *priv;
        struct device *dev;
        void *s_buf;
@@ -2468,12 +2464,7 @@ static int fcs_rng_read(struct hwrng *rng, void *buf, 
size_t max, bool wait)
 
        priv = (struct intel_fcs_priv *)rng->priv;
        dev = priv->client.dev;
-
-       msg = devm_kzalloc(dev, sizeof(*msg), GFP_KERNEL);
-       if (!msg) {
-               dev_err(dev, "failed to allocate msg buffer\n");
-               return -ENOMEM;
-       }
+       msg = &msg_var;
 
        s_buf = stratix10_svc_allocate_memory(priv->chan,
                                              RANDOM_NUMBER_SIZE);
@@ -2481,7 +2472,6 @@ static int fcs_rng_read(struct hwrng *rng, void *buf, 
size_t max, bool wait)
                dev_err(dev, "failed to allocate random number buffer\n");
                return -ENOMEM;
        }
-
        msg->command = COMMAND_FCS_RANDOM_NUMBER_GEN;
        msg->payload = s_buf;
        msg->payload_length = RANDOM_NUMBER_SIZE;
-- 
2.17.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#10874): 
https://lists.yoctoproject.org/g/linux-yocto/message/10874
Mute This Topic: https://lists.yoctoproject.org/mt/88692071/21656
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to